Skip to content

Fix logic bug in create_schedule() re. backfills #693

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

Merged
merged 4 commits into from
Nov 22, 2024
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
8 changes: 6 additions & 2 deletions temporalio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Comment on lines +5509 to +5510
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if input.backfill
else None,

Not really needed tbh, but not a big deal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also usual Python formatting style is to place parens around xxx if cond else yyy expressions when used as arguments so that ruff indents the expression:

            initial_patch = temporalio.api.schedule.v1.SchedulePatch(
                trigger_immediately=(
                    temporalio.api.schedule.v1.TriggerImmediatelyRequest(
                        overlap_policy=temporalio.api.enums.v1.ScheduleOverlapPolicy.ValueType(
                            input.schedule.policy.overlap
                        ),
                    )
                    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(
Expand Down
16 changes: 10 additions & 6 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,33 +1104,37 @@ 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),
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 [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)
Expand Down
Loading