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

eladkal 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 9c5c5c21f1 Deprecate `skip_exit_code` in `BashOperator` (#30734)
9c5c5c21f1 is described below

commit 9c5c5c21f1cc7e72c3d810021e66c708b6d54ef9
Author: eladkal <45845474+elad...@users.noreply.github.com>
AuthorDate: Wed Apr 19 14:52:03 2023 +0300

    Deprecate `skip_exit_code` in `BashOperator` (#30734)
---
 airflow/operators/bash.py    | 25 +++++++++++++++++--------
 tests/operators/test_bash.py |  6 +++---
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/airflow/operators/bash.py b/airflow/operators/bash.py
index 8450b1802d..da5e3bdf09 100644
--- a/airflow/operators/bash.py
+++ b/airflow/operators/bash.py
@@ -19,6 +19,7 @@ from __future__ import annotations
 
 import os
 import shutil
+import warnings
 from typing import Sequence
 
 from airflow.compat.functools import cached_property
@@ -51,16 +52,17 @@ class BashOperator(BaseOperator):
         from current passes and then environment variable passed by the user 
will either update the existing
         inherited environment variables or the new variables gets appended to 
it
     :param output_encoding: Output encoding of bash command
-    :param skip_exit_code: If task exits with this exit code, leave the task
+    :param skip_on_exit_code: If task exits with this exit code, leave the task
         in ``skipped`` state (default: 99). If set to ``None``, any non-zero
         exit code will be treated as a failure.
     :param cwd: Working directory to execute the command in.
         If None (default), the command is run in a temporary directory.
 
     Airflow will evaluate the exit code of the bash command. In general, a 
non-zero exit code will result in
-    task failure and zero will result in task success. Exit code ``99`` (or 
another set in ``skip_exit_code``)
+    task failure and zero will result in task success.
+    Exit code ``99`` (or another set in ``skip_on_exit_code``)
     will throw an :class:`airflow.exceptions.AirflowSkipException`, which will 
leave the task in ``skipped``
-    state. You can have all non-zero exit codes be treated as a failure by 
setting ``skip_exit_code=None``.
+    state. You can have all non-zero exit codes be treated as a failure by 
setting ``skip_on_exit_code=None``.
 
     .. list-table::
        :widths: 25 25
@@ -70,7 +72,7 @@ class BashOperator(BaseOperator):
          - Behavior
        * - 0
          - success
-       * - `skip_exit_code` (default: 99)
+       * - `skip_on_exit_code` (default: 99)
          - raise :class:`airflow.exceptions.AirflowSkipException`
        * - otherwise
          - raise :class:`airflow.exceptions.AirflowException`
@@ -140,7 +142,8 @@ class BashOperator(BaseOperator):
         env: dict[str, str] | None = None,
         append_env: bool = False,
         output_encoding: str = "utf-8",
-        skip_exit_code: int = 99,
+        skip_exit_code: int | None = None,
+        skip_on_exit_code: int = 99,
         cwd: str | None = None,
         **kwargs,
     ) -> None:
@@ -148,7 +151,13 @@ class BashOperator(BaseOperator):
         self.bash_command = bash_command
         self.env = env
         self.output_encoding = output_encoding
-        self.skip_exit_code = skip_exit_code
+        if skip_exit_code is not None:
+            warnings.warn(
+                "skip_exit_code is deprecated. Please use skip_on_exit_code", 
DeprecationWarning, stacklevel=2
+            )
+            self.skip_on_exit_code = skip_exit_code
+        else:
+            self.skip_on_exit_code = skip_on_exit_code
         self.cwd = cwd
         self.append_env = append_env
 
@@ -190,8 +199,8 @@ class BashOperator(BaseOperator):
             output_encoding=self.output_encoding,
             cwd=self.cwd,
         )
-        if self.skip_exit_code is not None and result.exit_code == 
self.skip_exit_code:
-            raise AirflowSkipException(f"Bash command returned exit code 
{self.skip_exit_code}. Skipping.")
+        if self.skip_on_exit_code is not None and result.exit_code == 
self.skip_on_exit_code:
+            raise AirflowSkipException(f"Bash command returned exit code 
{self.skip_on_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 ed423836f3..3c8320e1b2 100644
--- a/tests/operators/test_bash.py
+++ b/tests/operators/test_bash.py
@@ -173,9 +173,9 @@ class TestBashOperator:
         "extra_kwargs,actual_exit_code,expected_exc",
         [
             (None, 99, AirflowSkipException),
-            ({"skip_exit_code": 100}, 100, AirflowSkipException),
-            ({"skip_exit_code": 100}, 101, AirflowException),
-            ({"skip_exit_code": None}, 99, AirflowException),
+            ({"skip_on_exit_code": 100}, 100, AirflowSkipException),
+            ({"skip_on_exit_code": 100}, 101, AirflowException),
+            ({"skip_on_exit_code": None}, 99, AirflowException),
         ],
     )
     def test_skip(self, extra_kwargs, actual_exit_code, expected_exc):

Reply via email to