You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ep...@apache.org on 2024/03/31 15:57:35 UTC

(airflow) 10/19: Don't error when (un)pausing (un)paused dag in the CLI (#38585)

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

ephraimanierobi pushed a commit to branch v2-9-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit a06d4cd5d2d596c7b670fd7e4e681047290d9545
Author: Ephraim Anierobi <sp...@gmail.com>
AuthorDate: Thu Mar 28 15:39:36 2024 +0100

    Don't error when (un)pausing (un)paused dag in the CLI (#38585)
    
    If we find that the dag is unpaused already, we should just inform
    the user instead of raising error. Same with pausing
    
    (cherry picked from commit a64bb40a0f4fbe18939c479adae6a346734e5d35)
---
 airflow/cli/commands/dag_command.py    |  3 ++-
 tests/cli/commands/test_dag_command.py | 14 ++++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/airflow/cli/commands/dag_command.py b/airflow/cli/commands/dag_command.py
index 5ea8f3a6a2..2a8031cf90 100644
--- a/airflow/cli/commands/dag_command.py
+++ b/airflow/cli/commands/dag_command.py
@@ -230,7 +230,8 @@ def set_is_paused(is_paused: bool, args) -> None:
     ]
 
     if not dags:
-        raise AirflowException(f"No {'un' if is_paused else ''}paused DAGs were found")
+        print(f"No {'un' if is_paused else ''}paused DAGs were found")
+        return
 
     if not args.yes and args.treat_dag_id_as_regex:
         dags_ids = [dag.dag_id for dag in dags]
diff --git a/tests/cli/commands/test_dag_command.py b/tests/cli/commands/test_dag_command.py
index cc458b7cf7..cac538139b 100644
--- a/tests/cli/commands/test_dag_command.py
+++ b/tests/cli/commands/test_dag_command.py
@@ -707,10 +707,20 @@ class TestCliDags:
         with pytest.raises(AirflowException):
             dag_command.dag_pause(args)
 
-    def test_unpause_already_unpaused_dag_error(self):
+    def test_unpause_already_unpaused_dag_do_not_error(self):
         args = self.parser.parse_args(["dags", "unpause", "example_bash_operator", "--yes"])
-        with pytest.raises(AirflowException, match="No paused DAGs were found"):
+        with contextlib.redirect_stdout(StringIO()) as temp_stdout:
             dag_command.dag_unpause(args)
+            out = temp_stdout.getvalue().strip().splitlines()[-1]
+        assert out == "No paused DAGs were found"
+
+    def test_pausing_already_paused_dag_do_not_error(self):
+        args = self.parser.parse_args(["dags", "pause", "example_bash_operator", "--yes"])
+        with contextlib.redirect_stdout(StringIO()) as temp_stdout:
+            dag_command.dag_pause(args)
+            dag_command.dag_pause(args)
+            out = temp_stdout.getvalue().strip().splitlines()[-1]
+        assert out == "No unpaused DAGs were found"
 
     def test_trigger_dag(self):
         dag_command.dag_trigger(