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 logic bug in create_schedule() re. backfills #693

Merged
merged 4 commits into from
Nov 22, 2024

Conversation

josh-berry
Copy link
Contributor

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.

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.
@josh-berry josh-berry requested a review from a team as a code owner November 22, 2024 14:50
@dandavison
Copy link
Contributor

In general I like us to always create a failing test when fixing a bug. Have you looked into how difficult that would be to do here?

@josh-berry
Copy link
Contributor Author

I am unsure if this is worth adding tests for, but I can. I'd tried to tweak test_schedule_backfill() but that didn't work in the way I expect, so I'd have to spend some time actually learning how schedules work and writing a new test, I think.

@josh-berry
Copy link
Contributor Author

In general I like us to always create a failing test when fixing a bug. Have you looked into how difficult that would be to do here?

lol, we crossed on the wire. Yes, I think it would take me a couple (more) hours since I'm not really familiar with schedules. (That's not counting the hour or two I've already spent trying to tweak an existing test to validate this as well.)

@dandavison
Copy link
Contributor

Does any SDK have tests for this functionality? If so, we could appeal to an argument for coverage by analogy to the other SDK. (Also it might teach us how to provide coverage here.)

@josh-berry
Copy link
Contributor Author

Does any SDK have tests for this functionality? If so, we could appeal to an argument for coverage by analogy to the other SDK. (Also it might teach us how to provide coverage here.)

I don't believe this is relevant in any other SDK; TypeScript exposes schedule creation in a different way. Go is kinda similar but does not test this so far as I can see. Java also has a completely different approach using builders.

@josh-berry
Copy link
Contributor Author

hm, looking at some of the CI failures (which I did not see running locally that I can recall), I'm wondering if the existing tests actually ARE sufficient but were just wrong. I was hoping this would be straightforward but I think I'll need to dig more anyway.

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

LGTM, but will wait for @dandavison approval

Comment on lines +5509 to +5510
if input.backfill
else None,
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
                ),
            )

@josh-berry
Copy link
Contributor Author

OK, that actually didn't take as long as I thought. So it turns out test_schedule_backfill() actually was testing for the presence of the bug (it was counting an extra action which no longer happens if trigger_immediately is False). So I've updated the action counts accordingly and added some comments explaining how we arrived at the total action counts in the assertions.

@dandavison This should address your (and my) concern about preventing regressions in the future.

Copy link
Contributor

@dandavison dandavison left a comment

Choose a reason for hiding this comment

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

Nice, LGTM! I see (desired) test failures when I switch to main and checkout the tests from this branch:

FAILED tests/test_client.py::test_schedule_backfill - assert 3 in [1, 2]
FAILED tests/test_client.py::test_schedule_search_attribute_update - AssertionError: timed out waiting for equal, asserted against last value of 1

Are both those expected?

@josh-berry
Copy link
Contributor Author

schedule_backfills is yes, that's how we know we've fixed this bug. :) The search-attribute update one appears to be an unrelated intermittent failure.

@dandavison
Copy link
Contributor

schedule_backfills is yes, that's how we know we've fixed this bug. :)

Right (that's what I meant by desired failures). When reviewing I usually run the tests from the PR with the feature changes reverted to ensure that there is a test failure on main as there should be.

The search-attribute update one appears to be an unrelated intermittent failure.

OK great, I must have been having bad luck with that one.

@josh-berry josh-berry merged commit 853889c into main Nov 22, 2024
12 checks passed
@josh-berry josh-berry deleted the josh/create-sched-678 branch November 22, 2024 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Logic bug for create_schedule + backfill w/out trigger immediately
3 participants