Repository navigation
Conversation
crontab_parser matched each part with re.match, which only anchors at the start. A part such as '*/2-3', '1-10/2/3' or '1-5 x' matched a valid prefix and the rest was silently dropped, so crontab(minute='*/2-3') ran every two minutes instead of raising. The pyparsing grammar this parser replaced ended with StringEnd(); anchor the patterns at the end of the part so the whole part has to match.
There was a problem hiding this comment.
Checked at 3a8adf0. t/unit/app/test_schedules.py and t/unit/app/test_beat.py pass (376 passed, 11 skipped), and the five new cases fail on main.
Anchoring the patterns is the right idea, but a part that no longer matches falls through to _expand_number(), and that changes a few inputs in ways the tests don't cover. Comparing the fields that crontab(...) builds on main and on this branch:
main this PR
minute='*/2-3' every 2 min ValueError (intended)
minute='1-10/2/3' [1,3,5,7,9] ValueError (intended)
day_of_week='mon-fri x' [1..5] [1] <- Monday only, no error
day_of_week='mon-fri/2/3' [1, 3, 5] [1]
day_of_week='sat-sun ' [0, 6] [6]
month_of_year='jan-mar ' [1, 2, 3] [1]
minute='0-30 ' [0..30] ValueError
minute='*/15 ' [0,15,30,45] ValueError
minute='0-30 ,45' [0..30, 45] ValueError
minute='1-5\n' [1..5] [1..5] ($ also matches before a final newline)
- Day and month names are silently truncated. When the anchored range no longer matches,
_expand_number('mon-fri x')triesint()and thenyearmonth()/weekday(). Those only look at the first three letters, so the part becomes the first day or month. Forday_of_weekandmonth_of_yearthe PR therefore turns "wrong but close" into "silently wrong" rather than into an error, the opposite of what it set out to do._expand_numbershould only accept a bare token, e.g. raiseValueErrorunlessre.fullmatch(r'\w+', s)(or check before callingweekday()/yearmonth()). - Trailing whitespace is now rejected.
'0-30 'and'*/15 'used to parse and now raise, while'7 'still works (int()tolerates the space). Specs that come from env vars, YAML or ini files can carry a stray space, so this could break a beat schedule on upgrade. Stripping each part inparse()(part.strip()) before matching keeps the whitespace tolerance consistent and still rejects real trailing text. - Minor:
$also matches before a trailing newline, so'1-5\n'is still accepted.re.fullmatch(or\Z) would make the anchoring exact.
Tests for a day-name range with trailing text and for a part with surrounding whitespace would pin both cases.
The CI workflows for this commit are still waiting for maintainer approval.
|
isnt it covering a duplicate part of another pr? or it is fixing a different problem? |
|
Different problem, as far as I can tell. #10896 rejects day/month combinations that never occur (the 30th of February) and keeps beat alive when one entry fails. This one is in |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10891 +/- ##
=======================================
Coverage 91.21% 91.21%
=======================================
Files 153 153
Lines 21778 21781 +3
Branches 2701 2702 +1
=======================================
+ Hits 19865 19868 +3
Misses 1612 1612
Partials 301 301
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
…ailing-text # Conflicts: # CONTRIBUTORS.txt
Match each part with fullmatch after stripping surrounding whitespace, so '0-30 ' and '*/15 ' keep parsing as before, and make _expand_number accept only a bare token, so 'mon-fri x' raises instead of becoming Monday.
|
@MehrazRumman thanks, all three reproduce. Pushed 7f11911: each part is stripped and matched with |
Note: Before submitting this pull request, please review our contributing
guidelines.
Description
crontab_parsermatches each part withre.match, which only anchors at the start of the string. A part such as*/2-3,1-10/2/3or1-5 xmatches a valid prefix and the rest is silently dropped, socrontab(minute='*/2-3')runs every two minutes instead of raising. Invalid literals such asfooalready raiseValueError, so a typo in a beat schedule should too.The pyparsing grammar this parser replaced ended with
StringEnd(). This anchors the range, range/steps and star/steps patterns at the end of the part, so the whole part has to match; anything else falls through to the existing error path. Valid expressions (*/5,1-10/2,mon-fri/2, wrap-around ranges) parse as before.Added a parametrized test next to the other
test_parse_errors_on_*tests: its 5 cases fail on main and pass with the change.t/unit/app/test_schedules.pyandt/unit/app/test_beat.py: 376 passed, 11 skipped; flake8 clean.