Skip to content

Commit

Permalink
Fix AirflowSkipException message raised by BashOperator (#36354)
Browse files Browse the repository at this point in the history
(cherry picked from commit 667a5b2)
  • Loading branch information
dolfinus authored and ephraimbuddy committed Jan 11, 2024
1 parent 3c70325 commit d80d6a1
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 @@ -162,7 +162,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 @@ -206,8 +206,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 @@ -169,15 +169,23 @@ def test_valid_cwd(self, 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):
Expand Down

0 comments on commit d80d6a1

Please sign in to comment.