Skip to content

[v3-3-test] Add partition clear support to REST API matching the CLI (#68702)#68907

Merged
Lee-W merged 1 commit into
v3-3-testfrom
backport-a0805a8-v3-3-test
Jun 24, 2026
Merged

[v3-3-test] Add partition clear support to REST API matching the CLI (#68702)#68907
Lee-W merged 1 commit into
v3-3-testfrom
backport-a0805a8-v3-3-test

Conversation

@github-actions

Copy link
Copy Markdown
Contributor
  • API: Add partition clear support to REST API to match the CLI

clearDagRuns now accepts partition_key / partition_date window selectors
as an alternative to an explicit run list. Add POST /dags/{dag_id}/clearPartitions
to reset partition_key/partition_date on matching runs, with optional
task-instance clear — REST parity with airflow dags clear / airflow partitions clear.

  • API: Deduplicate partition selector fields across clear request bodies

Extract the shared partition_key / partition_date window fields and their date-order check into a PartitionSelectorMixin reused by BulkDAGRunClearBody and ClearPartitionsBody, and replace the repeated partition-selector presence checks with a has_partition_selectors property. No behavior change.

  • Scope partition-clear task instance queries to the target dag

Add a dag_id filter to the task-instance lookups in both the REST clear_partition_fields service and the airflow partitions clear CLI so a run_id shared across dags no longer clears another dag's task instances, and collapse the per-run dry-run task-instance lookups into a single batched count query.

  • Share the partition date-window filter across clear paths

Extract the resolve_day_bound partition_date window resolution duplicated across the REST clear_dag_runs route, the clear_partition_fields service, and the airflow partitions clear CLI into a single DagRun.apply_partition_date_window helper so the three cannot drift.

  • Share the partition-clear core between the REST API and the CLI

Extract the partition column-reset, task-instance batching, and dry-run counting into a single DagRun.clear_partition_runs helper reused by the clearPartitions REST endpoint and the airflow partitions clear CLI, replacing the two parallel implementations. The CLI keeps its per-run output through an optional callback. No behavior change.

  • Fix partition clear commands widening sub-day windows to the whole day

dags clear and partitions clear passed user-supplied datetimes
through resolve_day_bound(.date()), which stripped the time component
and expanded any sub-day bound to local midnight. On an hourly
partitioned Dag, --partition-date-start 08:00 --partition-date-end 08:00 cleared all 24 partitions instead of just the 08:00 one.

Adds localize_partition_datetime to the Timetable protocol (base:
UTC pass-through; CronMixin: wall-clock re-interpreted in the
timetable's local timezone, same logic as #68718). Removes the
now-redundant private _localize_wall_clock_to_timetable_timezone from
CronPartitionTimetable. Updates apply_partition_date_window to use
the new method with an inclusive <= end bound instead of the old
half-open < next_midnight form.

  • Update REST datamodel descriptions to reflect sub-day precision

  • Share partition selection-mode validation across clear request bodies

BulkDAGRunClearBody and ClearPartitionsBody duplicated the same
"exactly one selection mode" rule, including the partition-window
definition and the selector-enumeration error message, which would
drift independently. Move the shared check onto PartitionSelectorMixin
so the partition-selector semantics live in one place.

  • Drop sub-day-precision wording from partition clear CLI help

The "sub-day precision is preserved" phrasing framed the help against a
since-fixed truncation bug, which is meaningless to a reader seeing the
text fresh. The timezone re-interpretation note plus the date-only ->
midnight rule already convey that the time of day is honoured.

  • Remove unused resolve_day_bound

  • Refactor tests

  • regen docs

  • Fix test failure

  • Fix ruff F402 and docs spelling failing CI on partition-clear branch

A loop variable shadowed the imported task decorator (ruff F402) and a
British-spelled word in a new docstring tripped the en_US docs spell-check.


(cherry picked from commit a0805a8)

Co-authored-by: Wei Lee weilee.rx@gmail.com
Co-authored-by: Rahul Vats rah.sharma11@gmail.com

…68702)

* API: Add partition clear support to REST API to match the CLI

clearDagRuns now accepts partition_key / partition_date window selectors
as an alternative to an explicit run list. Add POST /dags/{dag_id}/clearPartitions
to reset partition_key/partition_date on matching runs, with optional
task-instance clear — REST parity with `airflow dags clear` / `airflow partitions clear`.

* API: Deduplicate partition selector fields across clear request bodies

Extract the shared partition_key / partition_date window fields and their date-order check into a PartitionSelectorMixin reused by BulkDAGRunClearBody and ClearPartitionsBody, and replace the repeated partition-selector presence checks with a has_partition_selectors property. No behavior change.

* Scope partition-clear task instance queries to the target dag

Add a dag_id filter to the task-instance lookups in both the REST clear_partition_fields service and the airflow partitions clear CLI so a run_id shared across dags no longer clears another dag's task instances, and collapse the per-run dry-run task-instance lookups into a single batched count query.

* Share the partition date-window filter across clear paths

Extract the resolve_day_bound partition_date window resolution duplicated across the REST clear_dag_runs route, the clear_partition_fields service, and the airflow partitions clear CLI into a single DagRun.apply_partition_date_window helper so the three cannot drift.

* Share the partition-clear core between the REST API and the CLI

Extract the partition column-reset, task-instance batching, and dry-run counting into a single DagRun.clear_partition_runs helper reused by the clearPartitions REST endpoint and the airflow partitions clear CLI, replacing the two parallel implementations. The CLI keeps its per-run output through an optional callback. No behavior change.

* Fix partition clear commands widening sub-day windows to the whole day

`dags clear` and `partitions clear` passed user-supplied datetimes
through `resolve_day_bound(.date())`, which stripped the time component
and expanded any sub-day bound to local midnight. On an hourly
partitioned Dag, `--partition-date-start 08:00 --partition-date-end
08:00` cleared all 24 partitions instead of just the 08:00 one.

Adds `localize_partition_datetime` to the `Timetable` protocol (base:
UTC pass-through; CronMixin: wall-clock re-interpreted in the
timetable's local timezone, same logic as #68718). Removes the
now-redundant private `_localize_wall_clock_to_timetable_timezone` from
`CronPartitionTimetable`. Updates `apply_partition_date_window` to use
the new method with an inclusive `<=` end bound instead of the old
half-open `< next_midnight` form.

* Update REST datamodel descriptions to reflect sub-day precision

* Share partition selection-mode validation across clear request bodies

BulkDAGRunClearBody and ClearPartitionsBody duplicated the same
"exactly one selection mode" rule, including the partition-window
definition and the selector-enumeration error message, which would
drift independently. Move the shared check onto PartitionSelectorMixin
so the partition-selector semantics live in one place.

* Drop sub-day-precision wording from partition clear CLI help

The "sub-day precision is preserved" phrasing framed the help against a
since-fixed truncation bug, which is meaningless to a reader seeing the
text fresh. The timezone re-interpretation note plus the date-only ->
midnight rule already convey that the time of day is honoured.

* Remove unused resolve_day_bound

* Refactor tests

* regen docs

* Fix test failure

* Fix ruff F402 and docs spelling failing CI on partition-clear branch

A loop variable shadowed the imported `task` decorator (ruff F402) and a
British-spelled word in a new docstring tripped the en_US docs spell-check.

---------
(cherry picked from commit a0805a8)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Co-authored-by: Rahul Vats <rah.sharma11@gmail.com>
@Lee-W Lee-W merged commit 50b6c1e into v3-3-test Jun 24, 2026
141 of 150 checks passed
@Lee-W Lee-W deleted the backport-a0805a8-v3-3-test branch June 24, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:airflow-ctl area:API Airflow's REST/HTTP API area:CLI area:UI Related to UI/UX. For Frontend Developers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant