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

husseinawala pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 667a5b2d29 Fix AirflowSkipException message raised by BashOperator 
(#36354)
667a5b2d29 is described below

commit 667a5b2d29c1ce46021d400fa591650855dcf26c
Author: Maxim Martynov <[email protected]>
AuthorDate: Fri Dec 22 01:51:04 2023 +0300

    Fix AirflowSkipException message raised by BashOperator (#36354)
---
 airflow/operators/bash.py    |  6 +++---
 tests/operators/test_bash.py | 22 +++++++++++++++-------
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/airflow/operators/bash.py b/airflow/operators/bash.py
index d913b2b282..ff8edcba51 100644
--- a/airflow/operators/bash.py
+++ b/airflow/operators/bash.py
@@ -160,7 +160,7 @@ class BashOperator(BaseOperator):
             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
@@ -235,8 +235,8 @@ class BashOperator(BaseOperator):
             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}."
diff --git a/tests/operators/test_bash.py b/tests/operators/test_bash.py
index fb2e4146bd..4903081747 100644
--- a/tests/operators/test_bash.py
+++ b/tests/operators/test_bash.py
@@ -188,15 +188,23 @@ class TestBashOperator:
     @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):

Reply via email to