Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in upsert search attribs #440

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions temporalio/worker/_workflow_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ def workflow_upsert_search_attributes(
# To apply to typed search attributes we remove, replace, or add. We
# don't know any of the key types, so we do our best.
index = next(
i for i, a in enumerate(mut_typed_attrs) if a.key.name == k
(i for i, a in enumerate(mut_typed_attrs) if a.key.name == k), None
)
if not vals:
if index is not None:
Expand Down Expand Up @@ -1285,9 +1285,12 @@ def workflow_upsert_search_attributes(

# Update typed and untyped in info
index = next(
i
for i, a in enumerate(mut_typed_attrs)
if a.key.name == update.key.name
(
i
for i, a in enumerate(mut_typed_attrs)
if a.key.name == update.key.name
),
None,
)
if update.value is None:
# Delete
Expand All @@ -1301,7 +1304,7 @@ def workflow_upsert_search_attributes(
update.key, update.value
)
if index is None:
mut_typed_attrs.append()
mut_typed_attrs.append(pair)
else:
mut_typed_attrs[index] = pair
# Single-item list if not already a sequence for untyped
Expand Down
29 changes: 29 additions & 0 deletions tests/worker/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,35 @@ async def describe_attributes_typed(
assert updated_attrs_typed == await describe_attributes_typed(handle)


@workflow.defn
class NoSearchAttributesWorkflow:
@workflow.run
async def run(self) -> None:
workflow.upsert_search_attributes(
[
SearchAttributeWorkflow.text_attribute.value_set("text2"),
]
)
# All we need to do is complete


async def test_workflow_no_initial_search_attributes(client: Client, env_type: str):
if env_type != "local":
pytest.skip("Only testing search attributes on local which disables cache")
await ensure_search_attributes_present(
client,
SearchAttributeWorkflow.text_attribute,
)
async with new_worker(client, NoSearchAttributesWorkflow) as worker:
handle = await client.start_workflow(
NoSearchAttributesWorkflow.run,
id=f"workflow-{uuid.uuid4()}",
task_queue=worker.task_queue,
# importantly, no initial search attributes
)
await handle.result()


@workflow.defn
class LoggingWorkflow:
def __init__(self) -> None:
Expand Down
Loading