From 853889c6936e40bbb33a130823d8517e9b4a6a62 Mon Sep 17 00:00:00 2001 From: Josh Berry Date: Fri, 22 Nov 2024 12:45:39 -0500 Subject: [PATCH] Fix logic bug in create_schedule() re. backfills (#693) Don't ask for immediate trigger when a backfill is requested, and don't ask for a backfill when an immediate trigger is requested. Closes #678. --- temporalio/client.py | 8 ++++++-- tests/test_client.py | 16 ++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/temporalio/client.py b/temporalio/client.py index 7e5992f7..72372e09 100644 --- a/temporalio/client.py +++ b/temporalio/client.py @@ -5502,8 +5502,12 @@ async def create_schedule(self, input: CreateScheduleInput) -> ScheduleHandle: overlap_policy=temporalio.api.enums.v1.ScheduleOverlapPolicy.ValueType( input.schedule.policy.overlap ), - ), - backfill_request=[b._to_proto() for b in input.backfill], + ) + if input.trigger_immediately + else None, + backfill_request=[b._to_proto() for b in input.backfill] + if input.backfill + else None, ) try: request = temporalio.api.workflowservice.v1.CreateScheduleRequest( diff --git a/tests/test_client.py b/tests/test_client.py index 03ce68ff..d779d6ea 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1104,6 +1104,9 @@ async def test_schedule_backfill( state=ScheduleState(paused=True), ), backfill=[ + # 2 actions on Server >= 1.24, 1 action on Server < 1.24. Older + # servers backfill workflows in the interval [start_at, end_at), but + # newer servers backfill the interval [start_at, end_at]. ScheduleBackfill( start_at=begin - timedelta(minutes=30), end_at=begin - timedelta(minutes=29), @@ -1111,26 +1114,27 @@ async def test_schedule_backfill( ) ], ) - # 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] + # We accept both 1.24 and pre-1.24 action counts + assert (await handle.describe()).info.num_actions in [1, 2] # Add two more backfills and and -2m will be deduped await handle.backfill( + # 3 actions on Server >= 1.24, 2 actions on Server < 1.24 ScheduleBackfill( start_at=begin - timedelta(minutes=4), end_at=begin - timedelta(minutes=2), overlap=ScheduleOverlapPolicy.ALLOW_ALL, ), + # 3 actions on Server >= 1.24, 2 actions on Server < 1.24, except on + # Server >= 1.24, there is overlap with the prior backfill, so this is + # only net +2 actions, regardless of Server version. ScheduleBackfill( start_at=begin - timedelta(minutes=2), end_at=begin, overlap=ScheduleOverlapPolicy.ALLOW_ALL, ), ) - # 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] + assert (await handle.describe()).info.num_actions in [5, 7] await handle.delete() await assert_no_schedules(client)