Skip to content

Commit

Permalink
Fix AirflowSkipException message raised by BashOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Dec 21, 2023
1 parent 0b32613 commit fa5fbf8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 3 additions & 3 deletions airflow/operators/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(
skip_on_exit_code
if isinstance(skip_on_exit_code, Container)
else [skip_on_exit_code]
if skip_on_exit_code
if skip_on_exit_code is not None
else []
)
self.cwd = cwd
Expand Down Expand Up @@ -235,8 +235,8 @@ def execute(self, context: Context):
output_encoding=self.output_encoding,
cwd=self.cwd,
)
if self.skip_on_exit_code is not None and result.exit_code in self.skip_on_exit_code:
raise AirflowSkipException(f"Bash command returned exit code {self.skip_on_exit_code}. Skipping.")
if result.exit_code in self.skip_on_exit_code:
raise AirflowSkipException(f"Bash command returned exit code {result.exit_code}. Skipping.")
elif result.exit_code != 0:
raise AirflowException(
f"Bash command failed. The command returned a non-zero exit code {result.exit_code}."
Expand Down
22 changes: 15 additions & 7 deletions tests/operators/test_bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,23 @@ def test_valid_cwd(self, context, tmp_path):
@pytest.mark.parametrize(
"extra_kwargs,actual_exit_code,expected_exc",
[
(None, 99, AirflowSkipException),
({"skip_on_exit_code": 100}, 100, AirflowSkipException),
({"skip_on_exit_code": 100}, 101, AirflowException),
({}, 0, None),
({}, 100, AirflowException),
({}, 99, AirflowSkipException),
({"skip_on_exit_code": None}, 0, None),
({"skip_on_exit_code": None}, 100, AirflowException),
({"skip_on_exit_code": None}, 99, AirflowException),
({"skip_on_exit_code": 100}, 0, None),
({"skip_on_exit_code": 100}, 100, AirflowSkipException),
({"skip_on_exit_code": 100}, 99, AirflowException),
({"skip_on_exit_code": 0}, 0, AirflowSkipException),
({"skip_on_exit_code": [100]}, 0, None),
({"skip_on_exit_code": [100]}, 100, AirflowSkipException),
({"skip_on_exit_code": (100, 101)}, 100, AirflowSkipException),
({"skip_on_exit_code": 100}, 101, AirflowException),
({"skip_on_exit_code": [100, 102]}, 101, AirflowException),
({"skip_on_exit_code": None}, 0, None),
({"skip_on_exit_code": [100]}, 99, AirflowException),
({"skip_on_exit_code": [100, 102]}, 99, AirflowException),
({"skip_on_exit_code": (100,)}, 0, None),
({"skip_on_exit_code": (100,)}, 100, AirflowSkipException),
({"skip_on_exit_code": (100,)}, 99, AirflowException),
],
)
def test_skip(self, extra_kwargs, actual_exit_code, expected_exc, context):
Expand Down

0 comments on commit fa5fbf8

Please sign in to comment.