Skip to content

Reject inverted date windows in airflow partitions clear#69454

Open
Lee-W wants to merge 3 commits into
apache:mainfrom
astronomer:partitions-clear-window-validation
Open

Reject inverted date windows in airflow partitions clear#69454
Lee-W wants to merge 3 commits into
apache:mainfrom
astronomer:partitions-clear-window-validation

Conversation

@Lee-W

@Lee-W Lee-W commented Jul 6, 2026

Copy link
Copy Markdown
Member

Why

airflow partitions clear silently reported no matching Dag runs when given an inverted date window — a --start-date later than --end-date, or a --date 'a~b' range where a is after b. 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 with dags clear --partition-date-start/--partition-date-end and the REST partition_date_start/partition_date_end fields, which already reject inverted
windows with the equivalent message.

What

  • Add an ordering check in partition_command.clear: when both bounds are present and start_date > end_date, raise SystemExit with --start-date must be on or before --end-date.
  • Apply the check uniformly to both input forms — explicit --start-date / --end-date flags and the --date 'a~b' range shorthand — by normalizing the parsed range into the same has_start / has_end bounds before validating.
  • Equal start and end dates remain valid (a single-day window).

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [Tool Name] following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {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.

@Lee-W Lee-W added the backport-to-v3-3-test Backport to v3-3-test label Jul 6, 2026
@Lee-W Lee-W self-assigned this Jul 6, 2026

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Lee-W added 3 commits July 7, 2026 17:55
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.
@Lee-W Lee-W force-pushed the partitions-clear-window-validation branch from 91a0480 to 9ec800d Compare July 7, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants