Skip to content

Commit

Permalink
Don't error when (un)pausing (un)paused dag in the CLI (apache#38585)
Browse files Browse the repository at this point in the history
If we find that the dag is unpaused already, we should just inform
the user instead of raising error. Same with pausing
  • Loading branch information
ephraimbuddy authored Mar 28, 2024
1 parent d566a8b commit a64bb40
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion airflow/cli/commands/dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 12 additions & 2 deletions tests/cli/commands/test_dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,20 @@ def test_pause_non_existing_dag_error(self):
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(
Expand Down

0 comments on commit a64bb40

Please sign in to comment.