Skip to content

Fix DAG.cli() crashing on dags pause and unpause - #72109

Merged
henry3260 merged 3 commits into
apache:mainfrom
Eason09053360:fix-dag-cli-pause-unpause-typeerror
Sep 5, 2026
Merged

Fix DAG.cli() crashing on dags pause and unpause#72109
henry3260 merged 3 commits into
apache:mainfrom
Eason09053360:fix-dag-cli-pause-unpause-typeerror

Conversation

@Eason09053360

@Eason09053360 Eason09053360 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

DAG.cli() dispatches every subcommand with the Dag object as a second
positional argument, because its parser drops --dag-id. The dags pause
and dags unpause handlers never accepted it, so running a Dag file as a
script raised TypeError: dag_pause() takes 1 positional argument but 2 were given instead of the command.

The regular airflow dags pause --dag-id foo path has always worked, which
is why this went unnoticed — the handlers are only reachable with two
arguments from a Dag file.

Only pause and unpause were affected. DAG_CLI_DICT resolves to exactly
six subcommands — dags list-runs/pause/unpause/test and tasks list/test
and the other four already accepted the Dag argument.

The filter at cli_config.py:2362 also lists backfill and run, but neither
name exists in DAGS_COMMANDS/TASKS_COMMANDS any more, so they match nothing.
Harmless today, and left alone here to keep this diff focused — but it is the
same fragility that hid this bug: two layers wired together by string matching,
with nothing enforcing that the names or the call signatures line up.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5) following the guidelines

A Dag file run as a script goes through DAG.cli(), whose parser drops
--dag-id and instead dispatches every subcommand with the Dag object as
a second positional argument. The pause and unpause handlers never
accepted it, so Dag authors got a TypeError instead of the command.

The handlers are only reachable this way from a Dag file, which is why
the regular `airflow dags pause` path has always worked and no test
covered the difference.

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work!

However, once the issue addressed in this PR is resolved, it seems to introduce another problem.

Comment thread airflow-core/src/airflow/cli/commands/dag_command.py
The Dag-scoped parser drops --dag-id but keeps --treat-dag-id-as-regex,
so the flag survives into a context where the user has no pattern left
to supply. The Dag's own id was then read back as a pattern, and dag_ids
may contain dots, so an unanchored match could pause unrelated Dags.

Normalising the flag next to the dag_id it guards covers both of its
readers, including the confirmation prompt, rather than guarding each
reader in turn and leaving the next one to be found later.

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, Looks great!

Let's wait for maintainer take a more look.

@henry3260 henry3260 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

Comment thread airflow-core/tests/unit/cli/commands/test_dag_command.py
@henry3260

Copy link
Copy Markdown
Contributor

Just applied change, i will merge when ci green :)

@henry3260 henry3260 added the backport-to-v3-3-test Backport to v3-3-test label Sep 5, 2026
@henry3260
henry3260 merged commit bcc430f into apache:main Sep 5, 2026
73 checks passed
@github-actions github-actions Bot added this to the Airflow 3.3.2 milestone Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 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.2 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 Sep 5, 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 Sep 5, 2026
…72109)

* Fix DAG.cli() crashing on dags pause and unpause

A Dag file run as a script goes through DAG.cli(), whose parser drops
--dag-id and instead dispatches every subcommand with the Dag object as
a second positional argument. The pause and unpause handlers never
accepted it, so Dag authors got a TypeError instead of the command.

The handlers are only reachable this way from a Dag file, which is why
the regular `airflow dags pause` path has always worked and no test
covered the difference.

* Ignore --treat-dag-id-as-regex when DAG.cli() supplies the Dag

The Dag-scoped parser drops --dag-id but keeps --treat-dag-id-as-regex,
so the flag survives into a context where the user has no pattern left
to supply. The Dag's own id was then read back as a pattern, and dag_ids
may contain dots, so an unanchored match could pause unrelated Dags.

Normalising the flag next to the dag_id it guards covers both of its
readers, including the confirmation prompt, rather than guarding each
reader in turn and leaving the next one to be found later.

* Update airflow-core/tests/unit/cli/commands/test_dag_command.py

---------
(cherry picked from commit bcc430f)

Co-authored-by: Y-C <easoneason0905@gmail.com>
Co-authored-by: Eason09053360 <185830721+Eason09053360@users.noreply.github.com>
Co-authored-by: Henry Chen <henryhenry0512@gmail.com>
henry3260 added a commit that referenced this pull request Sep 5, 2026
…#72565)

* Fix DAG.cli() crashing on dags pause and unpause

A Dag file run as a script goes through DAG.cli(), whose parser drops
--dag-id and instead dispatches every subcommand with the Dag object as
a second positional argument. The pause and unpause handlers never
accepted it, so Dag authors got a TypeError instead of the command.

The handlers are only reachable this way from a Dag file, which is why
the regular `airflow dags pause` path has always worked and no test
covered the difference.

* Ignore --treat-dag-id-as-regex when DAG.cli() supplies the Dag

The Dag-scoped parser drops --dag-id but keeps --treat-dag-id-as-regex,
so the flag survives into a context where the user has no pattern left
to supply. The Dag's own id was then read back as a pattern, and dag_ids
may contain dots, so an unanchored match could pause unrelated Dags.

Normalising the flag next to the dag_id it guards covers both of its
readers, including the confirmation prompt, rather than guarding each
reader in turn and leaving the next one to be found later.

* Update airflow-core/tests/unit/cli/commands/test_dag_command.py

---------
(cherry picked from commit bcc430f)

Co-authored-by: Y-C <easoneason0905@gmail.com>
Co-authored-by: Eason09053360 <185830721+Eason09053360@users.noreply.github.com>
Co-authored-by: Henry Chen <henryhenry0512@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.

3 participants