Reject inverted date windows in airflow partitions clear#69454
Open
Lee-W wants to merge 3 commits into
Open
Conversation
jason810496
approved these changes
Jul 7, 2026
jason810496
left a comment
Member
There was a problem hiding this comment.
Nice to have hardening before merging.
Comment on lines
+68
to
+72
| has_date_window = args.start_date is not None or args.end_date is not None | ||
| if has_start and has_end and args.start_date > args.end_date: | ||
| raise SystemExit("--start-date must be on or before --end-date.") |
Member
There was a problem hiding this comment.
When the inverted window comes from --date a~b, the error still says "--start-date must be on or before --end-date", naming flags the user did not type. Harmless but slightly confusing.
Comment on lines
-47
to
+49
| has_range = args.start_date is not None or args.end_date is not None or args.date is not None | ||
| has_start = args.start_date is not None | ||
| has_end = args.end_date is not None | ||
| has_range = has_start or has_end or args.date is not None |
Member
There was a problem hiding this comment.
Perhaps we can pre-validate the given date is yyyy-mm-dd format or not to avoid the following issue (thought it likely not happned):
window that is validly ordered in wall-clock terms but supplied with two different explicit UTC offsets (e.g. --start-date 2026-01-01T23:00:00-10:00 --end-date 2026-01-02T00:00:00+14:00) would be rejected by this guard even though the query would accept it.
The CLI silently reported no matching DagRuns for an inverted --start-date/--end-date window (or --date 'a~b' range) instead of rejecting it, unlike the equivalent `dags clear` and REST validations. Added the same ordering check with a matching error message.
…error When the inverted date window comes from --date a~b, the error previously said "--start-date must be on or before --end-date", naming flags the user never typed. It now names --date and echoes the two values the user supplied.
…alized comparison used downstream The guard compared --start-date/--end-date as absolute instants, but the downstream partition_date query re-interprets them through the Dag's timetable timezone, which for cron-based timetables discards the user-supplied UTC offset and re-localizes the wall-clock reading. A window that was wall-clock valid could be wrongly rejected, and one that was wall-clock inverted could be wrongly accepted. The guard now localizes both bounds the same way the query will before comparing.
91a0480 to
9ec800d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
airflow partitions clearsilently reported no matching Dag runs when given an inverted date window — a--start-datelater than--end-date, or a--date 'a~b'range whereais afterb. The command treated it as a valid-but-empty window instead of flagging the mistake, so a user who transposed the two dates got a misleading "nothing matched" result rather than an error. This is inconsistent withdags clear --partition-date-start/--partition-date-endand the RESTpartition_date_start/partition_date_endfields, which already reject invertedwindows with the equivalent message.
What
partition_command.clear: when both bounds are present andstart_date > end_date, raiseSystemExitwith--start-date must be on or before --end-date.--start-date/--end-dateflags and the--date 'a~b'range shorthand — by normalizing the parsed range into the samehas_start/has_endbounds before validating.Was generative AI tooling used to co-author this PR?
Generated-by: [Tool Name] following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.