Skip to content

Commit

Permalink
Server 1.24 related fixes (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
cretz authored Jun 17, 2024
1 parent 927415a commit 18b890e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 41 deletions.
6 changes: 5 additions & 1 deletion temporalio/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,11 @@ def updated(self, *search_attributes: SearchAttributePair) -> TypedSearchAttribu
# Go over each update, replacing matching keys by index or adding
for attr in search_attributes:
existing_index = next(
(i for i, attr in enumerate(attrs) if attr.key.name == attr.key.name),
(
i
for i, index_attr in enumerate(attrs)
if attr.key.name == index_attr.key.name
),
None,
)
if existing_index is None:
Expand Down
57 changes: 17 additions & 40 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,9 @@ async def test_schedule_backfill(
)
],
)
assert 2 == (await handle.describe()).info.num_actions
# The number of items backfilled on a schedule boundary changed in 1.24, so
# we check for either
assert (await handle.describe()).info.num_actions in [2, 3]

# Add two more backfills and and -2m will be deduped
await handle.backfill(
Expand All @@ -1073,7 +1075,9 @@ async def test_schedule_backfill(
overlap=ScheduleOverlapPolicy.ALLOW_ALL,
),
)
assert 6 == (await handle.describe()).info.num_actions
# The number of items backfilled on a schedule boundary changed in 1.24, so
# we check for either
assert (await handle.describe()).info.num_actions in [6, 8]

await handle.delete()
await assert_no_schedules(client)
Expand Down Expand Up @@ -1155,19 +1159,17 @@ def update_schedule_typed_attrs(
input.description.typed_search_attributes[text_attr_key]
== "some-schedule-attr1"
)
# This assertion has changed since server 1.24. Now, even untyped search
# attributes are given a type server side
assert (
input.description.schedule.action.typed_search_attributes
and len(input.description.schedule.action.typed_search_attributes) == 1
and len(input.description.schedule.action.typed_search_attributes) == 2
and input.description.schedule.action.typed_search_attributes[text_attr_key]
== "some-workflow-attr1"
)
assert (
input.description.schedule.action.untyped_search_attributes
and len(input.description.schedule.action.untyped_search_attributes) == 1
and input.description.schedule.action.untyped_search_attributes[
untyped_keyword_key.name
and input.description.schedule.action.typed_search_attributes[
untyped_keyword_key
]
== ["some-untyped-attr1"]
== "some-untyped-attr1"
)

# Update the workflow search attribute with a new typed value but does
Expand All @@ -1189,41 +1191,16 @@ def update_schedule_typed_attrs(
# Check that it changed
desc = await handle.describe()
assert isinstance(desc.schedule.action, ScheduleActionStartWorkflow)
# This assertion has changed since server 1.24. Now, even untyped search
# attributes are given a type server side
assert (
desc.schedule.action.typed_search_attributes
and len(desc.schedule.action.typed_search_attributes) == 1
and desc.schedule.action.typed_search_attributes[text_attr_key]
== "some-workflow-attr2"
)
assert (
desc.schedule.action.untyped_search_attributes
and len(desc.schedule.action.untyped_search_attributes) == 1
and desc.schedule.action.untyped_search_attributes[untyped_keyword_key.name]
== ["some-untyped-attr1"]
)

# Normal update with no typed attr change but remove untyped
def update_schedule_remove_untyped(
input: ScheduleUpdateInput,
) -> Optional[ScheduleUpdate]:
assert isinstance(
input.description.schedule.action, ScheduleActionStartWorkflow
)
input.description.schedule.action.untyped_search_attributes = {}
return ScheduleUpdate(input.description.schedule)

await handle.update(update_schedule_remove_untyped)

# Check that typed did not change but untyped did
desc = await handle.describe()
assert isinstance(desc.schedule.action, ScheduleActionStartWorkflow)
assert (
desc.schedule.action.typed_search_attributes
and len(desc.schedule.action.typed_search_attributes) == 1
and len(desc.schedule.action.typed_search_attributes) == 2
and desc.schedule.action.typed_search_attributes[text_attr_key]
== "some-workflow-attr2"
and desc.schedule.action.typed_search_attributes[untyped_keyword_key]
== "some-untyped-attr1"
)
assert not desc.schedule.action.untyped_search_attributes


async def assert_no_schedules(client: Client) -> None:
Expand Down

0 comments on commit 18b890e

Please sign in to comment.