Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AirflowSkipException message raised by BashOperator #36354

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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