[BUG]Invalid cron date schedule creates infinite loop in flytescheduler - #3312
Conversation
Signed-off-by: Alex Wu <c.alexwu@gmail.com>
Signed-off-by: Alex Wu <c.alexwu@gmail.com>
| # Check if the cron expression can actually produce valid dates | ||
| try: | ||
| # Try to get the next occurrence to validate the schedule | ||
| cron.get_next(datetime.datetime) |
There was a problem hiding this comment.
Can we combine this check with above so that we do not need to have two try...except block
There was a problem hiding this comment.
btw is there any .validate() function that we can use instead of using get_next()?
There was a problem hiding this comment.
I suggest keeping them separate, and here's why:
- The first try block checks syntax: Whether
scheduleis a valid cron expression - The second try block checks semantics: Whether the expression can generate valid dates
If they're combined together, the error handling would become generic and make it harder for users to pinpoint the actual problem.
@machichima, WDYT?
There was a problem hiding this comment.
Then how about adding Error: {str(e)} in the end of the error message?
While those two try...expect are just alike, I would still prefer merging them together. But I agree that we should print the error out here so that we know the actual problem
There was a problem hiding this comment.
Sounds reasonable, let's merge them together and throw out the error message so users can understand whether it's a syntax error or semantic one.
There was a problem hiding this comment.
@machichima @JiangJiaWei1103 Thank you both for the advice. I've merged two try..except blocks into one.
There was a problem hiding this comment.
btw is there any
.validate()function that we can use instead of usingget_next()?
@machichima I think the only way for croniter to validate cron date is calling get_next function. I'm not sure whether we can do the validation by others cron library, yet I prefer to keep using croniter as it is a simple way.
| invalid_schedules = [ | ||
| "0 0 31 2 *", # February 31st (does not exist) | ||
| "0 0 30 2 *", # February 30th (does not exist) | ||
| "0 0 31 4 *", # April 31st (does not exist) | ||
| "0 0 31 6 *", # June 31st (does not exist) | ||
| ] |
There was a problem hiding this comment.
Consider using @pytest.parametrize() to represent multiple test cases?
Signed-off-by: Alex Wu <c.alexwu@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3312 +/- ##
===========================================
- Coverage 85.26% 41.15% -44.11%
===========================================
Files 386 250 -136
Lines 30276 25038 -5238
Branches 2969 2950 -19
===========================================
- Hits 25814 10304 -15510
- Misses 3615 14631 +11016
+ Partials 847 103 -744 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…er (flyteorg#3312) Signed-off-by: Alex Wu <c.alexwu@gmail.com> Signed-off-by: Atharva <atharvakulkarni172003@gmail.com>
Tracking issue
Related to #6470
Why are the changes needed?
In the Flytekit SDK, it is proposed that an error be raised if the user enters a cron job with an invalid date (e.g., 0 0 31 2 *), preventing the schedule from being sent to the backend.
What changes were proposed in this pull request?
Add schedule date validation check in flytekit SDK.
How was this patch tested?
Test workflow:
After registering the launch_plan with invalid schedule date, the SDK throws error as expected.

Check all the applicable boxes
Summary by Bito
This pull request fixes a bug in the Flytekit SDK related to invalid cron date schedules that could cause an infinite loop by adding validation for cron schedules. It introduces error handling for invalid cron expressions and includes comprehensive tests to ensure correct behavior for both valid and invalid inputs, improving the scheduling feature's robustness.