You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Eason09053360 (via GitHub)" <gi...@apache.org> on 2026/08/26 16:32:25 UTC

[PR] Fix DAG.cli() crashing on dags pause and unpause [airflow]

Eason09053360 opened a new pull request, #72109:
URL: https://github.com/apache/airflow/pull/72109

   `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.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Opus 5)
   
   Generated-by: Claude Code (Opus 5) following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix DAG.cli() crashing on dags pause and unpause [airflow]

Posted by "ColtenOuO (via GitHub)" <gi...@apache.org>.
ColtenOuO commented on code in PR #72109:
URL: https://github.com/apache/airflow/pull/72109#discussion_r3866311650


##########
airflow-core/src/airflow/cli/commands/dag_command.py:
##########


Review Comment:
   When dag is not None (called from `DAG.cli()`), args.dag_id is overwritten with `dag.dag_id`, but `args.treat_dag_id_as_regex` isn't reset. The dag-specific parser has no way for the user to supply a pattern, yet a stray `--treat-dag-id-as-regex` flag will treat `dag.dag_id` itself as regex -- dots in `dag_ids` (e.g. `foo.bar`) then match unrelated DAGs like `fooXbar`.
   
   uggest forcing exact match when called with a dag:
   
   
   ```suggestion
   if dag is None and args.treat_dag_id_as_regex:
       query = query.where(DagModel.dag_id.regexp_match(args.dag_id))
   else:
       query = query.where(DagModel.dag_id == args.dag_id)
   ```
   
   I think we also need add a test with a `dag_id` containing regex metacharacters.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix DAG.cli() crashing on dags pause and unpause [airflow]

Posted by "henry3260 (via GitHub)" <gi...@apache.org>.
henry3260 commented on PR #72109:
URL: https://github.com/apache/airflow/pull/72109#issuecomment-5552739810

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix DAG.cli() crashing on dags pause and unpause [airflow]

Posted by "henry3260 (via GitHub)" <gi...@apache.org>.
henry3260 commented on code in PR #72109:
URL: https://github.com/apache/airflow/pull/72109#discussion_r3941040985


##########
airflow-core/tests/unit/cli/commands/test_dag_command.py:
##########
@@ -564,6 +564,31 @@ def test_pause(self):
         dag_command.dag_unpause(args)
         assert not DagModel.get_dagmodel("example_bash_operator").is_paused
 
+    def test_pause_unpause_from_dag_cli(self):
+        """``DAG.cli()`` passes the Dag positionally and its parser drops ``--dag-id``."""
+        parser = cli_parser.get_parser(dag_parser=True)
+        dag = DAG("example_bash_operator")
+
+        dag_command.dag_pause(parser.parse_args(["dags", "pause"]), dag)
+        assert DagModel.get_dagmodel("example_bash_operator").is_paused
+
+        dag_command.dag_unpause(parser.parse_args(["dags", "unpause"]), dag)
+        assert not DagModel.get_dagmodel("example_bash_operator").is_paused
+
+    @mock.patch("airflow.cli.commands.dag_command.ask_yesno")
+    def test_pause_from_dag_cli_ignores_treat_dag_id_as_regex(self, mock_yesno):
+        """The Dag fixes the target, so its dag_id must not be read back as a pattern."""
+        target = DAG("dag.cli_regex_target")
+        sync_dag_to_db(target)
+        sync_dag_to_db(DAG("dagXcli_regex_target"))
+        parser = cli_parser.get_parser(dag_parser=True)
+
+        dag_command.dag_pause(parser.parse_args(["dags", "pause", "--treat-dag-id-as-regex"]), target)
+
+        mock_yesno.assert_not_called()
+        assert DagModel.get_dagmodel("dag.cli_regex_target").is_paused
+        assert not DagModel.get_dagmodel("dagXcli_regex_target").is_paused

Review Comment:
   This test syncs two extra Dags into `DagModel` and leaves one of them paused, but never cleans them up. `TestCliDags` only rebuilds the example Dags once in `setup_class` and clears them in `teardown_class`, so these rows stay visible to every test that runs after this one in the class. Other tests in this class that add their own Dags (e.g. `test_next_execution`, `test_cli_list_dags_with_multiple_dag_versions`) restore the shared state at the end.
   
   ```suggestion
           assert not DagModel.get_dagmodel("dagXcli_regex_target").is_paused
   
           clear_db_dags()
           self.setup_class()
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix DAG.cli() crashing on dags pause and unpause [airflow]

Posted by "henry3260 (via GitHub)" <gi...@apache.org>.
henry3260 merged PR #72109:
URL: https://github.com/apache/airflow/pull/72109


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix DAG.cli() crashing on dags pause and unpause [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #72109:
URL: https://github.com/apache/airflow/pull/72109#issuecomment-5553135322

   ### Backport successfully created: v3-3-test
   
   Note: As of [Merging PRs targeted for Airflow 3.X](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#merging-prs-targeted-for-airflow-3x)
   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](https://apache-airflow.slack.com/archives/C03G9H97MM2) Slack channel.
   
   <table>
           <tr>
           <th>Status</th>
           <th>Branch</th>
           <th>Result</th>
       </tr>
       <tr>
           <td>✅</td>
           <td>v3-3-test</td>
           <td><a href="https://github.com/apache/airflow/pull/72565"><img src="https://img.shields.io/badge/PR-72565-blue" alt="PR Link"></a></td>
       </tr>
   </table>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix DAG.cli() crashing on dags pause and unpause [airflow]

Posted by "ColtenOuO (via GitHub)" <gi...@apache.org>.
ColtenOuO commented on code in PR #72109:
URL: https://github.com/apache/airflow/pull/72109#discussion_r3866311650


##########
airflow-core/src/airflow/cli/commands/dag_command.py:
##########


Review Comment:
   When dag is not None (called from `DAG.cli()`), args.dag_id is overwritten with `dag.dag_id`, but `args.treat_dag_id_as_regex` isn't reset. The dag-specific parser has no way for the user to supply a pattern, yet a stray `--treat-dag-id-as-regex` flag will treat `dag.dag_id` itself as regex -- dots in `dag_ids` (e.g. `foo.bar`) then match unrelated DAGs like `fooXbar`.
   
   suggest forcing exact match when called with a dag:
   
   
   ```suggestion
   if dag is None and args.treat_dag_id_as_regex:
       query = query.where(DagModel.dag_id.regexp_match(args.dag_id))
   else:
       query = query.where(DagModel.dag_id == args.dag_id)
   ```
   
   I think we also need add a test with a `dag_id` containing regex metacharacters.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix DAG.cli() crashing on dags pause and unpause [airflow]

Posted by "Eason09053360 (via GitHub)" <gi...@apache.org>.
Eason09053360 commented on code in PR #72109:
URL: https://github.com/apache/airflow/pull/72109#discussion_r3869093971


##########
airflow-core/src/airflow/cli/commands/dag_command.py:
##########


Review Comment:
   Good catch — confirmed, and it's even worse than the example: regexp_match is unanchored on Postgres (~) and MySQL (REGEXP), so foo.bar also matches things like `staging_fooXbar_v2`, not just `fooXbar`.
   
   I went with normalising the flag at its source instead of guarding the query:
   
   
    `if dag:`
       `args.dag_id = dag.dag_id`
       `args.treat_dag_id_as_regex = False`
   The reason is that `args.treat_dag_id_as_regex` has two readers, and the suggested change only covers the first one. With it applied, the query is correct but the confirmation branch below still fires — I verified this, ask_yesno gets called with `"You are about to pause 1 DAGs:\ndag.cli_regex_target\n\nAre you sure? [y/n]"`, which would block on stdin in real use. Fixing the value covers both readers, and any future one.
   
   Added the test: `dag.cli_regex_target and dagXcli_regex_target` both in the DB, invoked through the Dag-scoped parser with --treat-dag-id-as-regex. It asserts the sibling is untouched and that ask_yesno is never called. Without the fix both Dags get paused.
   
   Also renamed the `dag` loop variable in the comprehension below to `dag_model`, since it now shadows the new parameter.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix DAG.cli() crashing on dags pause and unpause [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #72109:
URL: https://github.com/apache/airflow/pull/72109#issuecomment-5553133952

   Hi maintainer, this PR was merged without a milestone set.
   We've automatically set the milestone to **[Airflow 3.3.2](https://github.com/apache/airflow/milestone/150)** 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](https://github.com/apache/airflow/blob/main/.github/workflows/milestone-tag-assistant.yml).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org