Add airflowctl dags clear command - #68706
Merged
Merged
Conversation
1 task
The Dag run list endpoint declares the partition window as partition_date_gte / partition_date_lte. The names the command sent belong to the request body of a different route, and FastAPI drops query params it does not declare, so the window was silently discarded and every run of the Dag came back — and was cleared. partition_date_gt / partition_date_lt are not query params on that endpoint either, so they could never have filtered anything.
henry3260
force-pushed
the
add-airflowctl-dags-clear
branch
from
July 29, 2026 09:36
4cac9a5 to
5500c51
Compare
Nothing ever passed logical_date_gt or logical_date_lt, and documenting them broke the docs build: the spelling wordlist carries gte and lte but not gt and lt, so the generated API docs failed spell-checking.
DagRunOperations gained a private clear helper that duplicated the existing TasksOperations.clear. Because the CLI is generated from the operation classes, that helper also surfaced as a subcommand named "-clear-task-instances" with no help text. The Dag run list filters for run ID and partition key prefix had no callers either.
The new arguments landed under the "# Task Commands Args" heading, so anyone looking for what "dags clear" accepts would not find them in the Dag section where they belong.
The partition date ordering check sat in the function that fetches Dag runs while every other check lived in the validator, so a reader had to look in two places to learn what the command rejects. Parsing the window up front also removes a branch that could never be taken.
henry3260
marked this pull request as ready for review
July 29, 2026 17:31
henry3260
requested review from
bugraoz93,
dheerajturaga and
potiuk
as code owners
July 29, 2026 17:31
Contributor
Author
Thanks for review! |
Contributor
Backport failed to create: airflow-ctl/v0-1-test. View the failure log Run detailsNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
You can attempt to backport this manually by running: cherry_picker 07f5458 airflow-ctl/v0-1-testThis should apply the commit to the airflow-ctl/v0-1-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf you don't have cherry-picker installed, see the installation guide. |
dabla
pushed a commit
to dabla/airflow
that referenced
this pull request
Aug 14, 2026
* Add airflowctl dags clear command * Fix airflowctl dags clear ignoring the partition date window The Dag run list endpoint declares the partition window as partition_date_gte / partition_date_lte. The names the command sent belong to the request body of a different route, and FastAPI drops query params it does not declare, so the window was silently discarded and every run of the Dag came back — and was cleared. partition_date_gt / partition_date_lt are not query params on that endpoint either, so they could never have filtered anything. * Drop unused Dag run logical date filters from airflowctl Nothing ever passed logical_date_gt or logical_date_lt, and documenting them broke the docs build: the spelling wordlist carries gte and lte but not gt and lt, so the generated API docs failed spell-checking. * Reuse the tasks clear operation for airflowctl dags clear DagRunOperations gained a private clear helper that duplicated the existing TasksOperations.clear. Because the CLI is generated from the operation classes, that helper also surfaced as a subcommand named "-clear-task-instances" with no help text. The Dag run list filters for run ID and partition key prefix had no callers either. * Group airflowctl dags clear arguments with the other Dag arguments The new arguments landed under the "# Task Commands Args" heading, so anyone looking for what "dags clear" accepts would not find them in the Dag section where they belong. * Consolidate airflowctl dags clear argument validation in one place The partition date ordering check sat in the function that fetches Dag runs while every other check lived in the validator, so a reader had to look in two places to learn what the command rejects. Parsing the window up front also removes a branch that could never be taken.
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
This adds
airflowctl dags clearso those Dag runs can be selected declaratively and cleared in one command, with a confirmation prompt before anything is modified.What
New command —
airflow-ctl/src/airflowctl/ctl/cli_config.py,airflow-ctl/src/airflowctl/ctl/commands/dag_command.py,airflow-ctl/src/airflowctl/ctl/help_texts.yaml:airflowctl dags clear DAG_IDselects Dag runs by exactly one of--run-id,--partition-key, or the--partition-date-start/--partition-date-endwindow, and clears each selected run's task instances via the existing
tasks.clearoperation (reset_dag_runs=True).--only-failed/--only-runningnarrow which task instances are cleared;--yesskips the confirmation prompt. Without--yesthe command prints thematching Dag runs and asks before clearing.
the partition-date bounds must be supplied together and in order,
--only-failedand--only-runningare mutually exclusive, and unparsabledates are rejected up front — before any API call is made.
YYYY-MM-DDor a full ISO 8601 datetime; only thecalendar day is used, matching how the API interprets
partition_datein theDag's timetable timezone.
--partition-keymatches exactly. The API filter is a pattern filter, so thereturned page is additionally filtered client-side to drop prefix matches such
as
customer-a-suffix.page limit, so a large selection is not silently truncated.
API client —
airflow-ctl/src/airflowctl/api/operations.py:DagRunOperations.listgainedoffset,partition_date_gte,partition_date_lte, andpartition_key_pattern, matching the queryparameters the
GET /dags/{dag_id}/dagRunsendpoint actually declares. FastAPIsilently drops query params it does not declare, so a mismatched name would
return an unfiltered list — and the command would clear every run of the Dag.
_serialize_query_paramnow serializesdatetime.dateas well asdatetime.datetime.cli_config.CommandFactorylearned to map thedatetime.dateannotation tothe corresponding argparse type.
Docs —
airflow-ctl/docs/images/output_dags.svgandcommand_hashes.txtregenerated for the new subcommand.
related: #68402
Was generative AI tooling used to co-author this PR?