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

Avoid croniter infinite loop #5957

Merged
merged 5 commits into from Jul 3, 2022
Merged

Avoid croniter infinite loop #5957

merged 5 commits into from Jul 3, 2022

Conversation

jlowin
Copy link
Member

@jlowin jlowin commented Jul 3, 2022

Summary

We thought we had identified all the weird DST issues with croniter, but a user recently stumbled across a new one. A simplified demo:

import pendulum
from croniter import croniter
from datetime import datetime

cron = croniter('0 0 * * 0', pendulum.datetime(2022, 8, 21, tz='America/Santiago'))
for i in range(10):
    print(cron.next(datetime))

Which results in

2022-08-28 00:00:00-04:00
2022-09-03 23:00:00-04:00
2022-09-03 23:00:00-04:00
2022-09-03 23:00:00-04:00
2022-09-03 23:00:00-04:00
2022-09-03 23:00:00-04:00
2022-09-03 23:00:00-04:00
2022-09-03 23:00:00-04:00
2022-09-03 23:00:00-04:00
2022-09-03 23:00:00-04:00

To avoid this (and others potentially lurking), this adds a check to see if we're stuck in a date loop when evaluating cron. If so, we exit the loop by creating a new cron instance that begins yielding immediately AFTER the date question.

Changes

Fixes a bug where certain DST conditions put schedules into an infinite loop

Importance

Checklist

This PR:

  • adds new tests (if appropriate)
  • adds a change file in the changes/ directory (if appropriate)
  • updates docstrings for any new functions or function arguments, including docs/outline.toml for API reference docs (if appropriate)

@jlowin jlowin requested a review from zanieb as a code owner July 3, 2022 14:05
Copy link
Contributor

@jawnsy jawnsy left a comment

Choose a reason for hiding this comment

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

LGTM

@zanieb zanieb merged commit 701e7c5 into master Jul 3, 2022
@zanieb zanieb deleted the avoid-croniter-loop branch July 3, 2022 15:42
zanieb pushed a commit that referenced this pull request Jul 3, 2022
* Avoid croniter loop

* Update test_clocks.py

* Create PR5957.yaml

* mypy

* Update clocks.py
@zanieb zanieb mentioned this pull request Jul 5, 2022
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.

None yet

3 participants