This is an automated email from the ASF dual-hosted git repository.

henry3260 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 27b8c82f54d Restore "Nothing to clear." in airflow tasks clear (#76277)
27b8c82f54d is described below

commit 27b8c82f54d44830176eb049f2e42916c7849bb0
Author: Y-C <[email protected]>
AuthorDate: Mon Nov 2 15:15:41 2026 +0800

    Restore "Nothing to clear." in airflow tasks clear (#76277)
    
    An empty clear exited 0 with no output, which looks exactly like a
    successful clear: a mistyped --task-regex, --only-failed with no failed
    tasks, or an empty date range gave no hint that nothing happened.
    Airflow 2 reported these cases with "Nothing to clear."; the message was
    lost when the command moved off airflow.models.DAG. The exit code stays 0.
    
    Co-authored-by: Eason09053360 
<[email protected]>
---
 airflow-core/src/airflow/cli/commands/task_command.py  |  5 ++++-
 .../tests/unit/cli/commands/test_task_command.py       | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/airflow-core/src/airflow/cli/commands/task_command.py 
b/airflow-core/src/airflow/cli/commands/task_command.py
index 365278a4b5f..e147997bd9e 100644
--- a/airflow-core/src/airflow/cli/commands/task_command.py
+++ b/airflow-core/src/airflow/cli/commands/task_command.py
@@ -625,15 +625,18 @@ def task_clear(args) -> None:
             dry_run=True,
         )
         if not tis:
+            print("Nothing to clear.")
             return
         if not ask_yesno(f"You are about to delete these {len(tis)} 
tasks:\n{tis}\n\nAre you sure? [y/n]"):
             print("Cancelled, nothing was cleared.")
             return
 
-    SerializedDAG.clear_dags(
+    cleared = SerializedDAG.clear_dags(
         dags,
         start_date=args.start_date,
         end_date=args.end_date,
         only_failed=args.only_failed,
         only_running=args.only_running,
     )
+    if not cleared:
+        print("Nothing to clear.")
diff --git a/airflow-core/tests/unit/cli/commands/test_task_command.py 
b/airflow-core/tests/unit/cli/commands/test_task_command.py
index 0e305084977..72f5519ebbc 100644
--- a/airflow-core/tests/unit/cli/commands/test_task_command.py
+++ b/airflow-core/tests/unit/cli/commands/test_task_command.py
@@ -828,6 +828,24 @@ class TestCliTasks:
         (dags,) = mock_clear_dags.call_args.args
         assert set(dags[0].task_ids) == expected_task_ids
 
+    @pytest.mark.parametrize(
+        ("extra_args", "clear_dags_result", "expected_stdout"),
+        [
+            pytest.param(["--yes"], 0, "Nothing to clear.\n", 
id="yes-nothing-cleared"),
+            pytest.param(["--yes"], 3, "", id="yes-tasks-cleared"),
+            pytest.param([], [], "Nothing to clear.\n", 
id="prompt-nothing-to-clear"),
+        ],
+    )
+    @mock.patch("airflow.cli.commands.task_command.SerializedDAG.clear_dags", 
autospec=True)
+    def test_task_clear_reports_nothing_to_clear(
+        self, mock_clear_dags, capsys, extra_args, clear_dags_result, 
expected_stdout
+    ):
+        mock_clear_dags.return_value = clear_dags_result
+        args = self.parser.parse_args(["tasks", "clear", 
"example_bash_operator", *extra_args])
+        task_command.task_clear(args)
+
+        assert capsys.readouterr().out == expected_stdout
+
     def 
test_task_clear_task_regex_invalid_pattern_reported_before_dag_lookup(self):
         args = self.parser.parse_args(["tasks", "clear", "no_such_dag", 
"--task-regex", "runme_[", "--yes"])
         with pytest.raises(SystemExit, match=r"Invalid --task-regex 
'runme_\['"):

Reply via email to