Skip to content

Commit 853889c

Browse files
authored
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.
1 parent 97a2b7a commit 853889c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

temporalio/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5502,8 +5502,12 @@ async def create_schedule(self, input: CreateScheduleInput) -> ScheduleHandle:
55025502
overlap_policy=temporalio.api.enums.v1.ScheduleOverlapPolicy.ValueType(
55035503
input.schedule.policy.overlap
55045504
),
5505-
),
5506-
backfill_request=[b._to_proto() for b in input.backfill],
5505+
)
5506+
if input.trigger_immediately
5507+
else None,
5508+
backfill_request=[b._to_proto() for b in input.backfill]
5509+
if input.backfill
5510+
else None,
55075511
)
55085512
try:
55095513
request = temporalio.api.workflowservice.v1.CreateScheduleRequest(

tests/test_client.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,33 +1104,37 @@ async def test_schedule_backfill(
11041104
state=ScheduleState(paused=True),
11051105
),
11061106
backfill=[
1107+
# 2 actions on Server >= 1.24, 1 action on Server < 1.24. Older
1108+
# servers backfill workflows in the interval [start_at, end_at), but
1109+
# newer servers backfill the interval [start_at, end_at].
11071110
ScheduleBackfill(
11081111
start_at=begin - timedelta(minutes=30),
11091112
end_at=begin - timedelta(minutes=29),
11101113
overlap=ScheduleOverlapPolicy.ALLOW_ALL,
11111114
)
11121115
],
11131116
)
1114-
# The number of items backfilled on a schedule boundary changed in 1.24, so
1115-
# we check for either
1116-
assert (await handle.describe()).info.num_actions in [2, 3]
1117+
# We accept both 1.24 and pre-1.24 action counts
1118+
assert (await handle.describe()).info.num_actions in [1, 2]
11171119

11181120
# Add two more backfills and and -2m will be deduped
11191121
await handle.backfill(
1122+
# 3 actions on Server >= 1.24, 2 actions on Server < 1.24
11201123
ScheduleBackfill(
11211124
start_at=begin - timedelta(minutes=4),
11221125
end_at=begin - timedelta(minutes=2),
11231126
overlap=ScheduleOverlapPolicy.ALLOW_ALL,
11241127
),
1128+
# 3 actions on Server >= 1.24, 2 actions on Server < 1.24, except on
1129+
# Server >= 1.24, there is overlap with the prior backfill, so this is
1130+
# only net +2 actions, regardless of Server version.
11251131
ScheduleBackfill(
11261132
start_at=begin - timedelta(minutes=2),
11271133
end_at=begin,
11281134
overlap=ScheduleOverlapPolicy.ALLOW_ALL,
11291135
),
11301136
)
1131-
# The number of items backfilled on a schedule boundary changed in 1.24, so
1132-
# we check for either
1133-
assert (await handle.describe()).info.num_actions in [6, 8]
1137+
assert (await handle.describe()).info.num_actions in [5, 7]
11341138

11351139
await handle.delete()
11361140
await assert_no_schedules(client)

0 commit comments

Comments
 (0)