Skip to content

Reject inverted date windows in airflow partitions clear#69454

Merged
Lee-W merged 3 commits into
apache:mainfrom
astronomer:partitions-clear-window-validation
Jul 7, 2026
Merged

Reject inverted date windows in airflow partitions clear#69454
Lee-W merged 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 thread airflow-core/src/airflow/cli/commands/partition_command.py Outdated
Comment thread airflow-core/src/airflow/cli/commands/partition_command.py
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
@Lee-W Lee-W merged commit 1ff2114 into apache:main Jul 7, 2026
73 checks passed
@Lee-W Lee-W deleted the partitions-clear-window-validation branch July 7, 2026 13:35
@github-actions github-actions Bot added this to the Airflow 3.3.1 milestone Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.3.1 based on: backport label targeting v3-3-test
If this milestone is not correct, please update it to the appropriate milestone.

This comment was generated by Milestone Tag Assistant.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-3-test PR Link

github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Jul 7, 2026
…pache#69454)

(cherry picked from commit 1ff2114)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Jul 7, 2026
…pache#69454)

(cherry picked from commit 1ff2114)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
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