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

potiuk 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 81790aaaa0 Fix deprecated `DockerOperator` operator arguments in 
`MappedOperator` (#38379)
81790aaaa0 is described below

commit 81790aaaa029fe4e5102b25fce002e2e0f3c69db
Author: Andrey Anshin <[email protected]>
AuthorDate: Sun Mar 24 20:36:27 2024 +0400

    Fix deprecated `DockerOperator` operator arguments in `MappedOperator` 
(#38379)
---
 airflow/providers/docker/operators/docker.py    |  7 +++-
 tests/providers/docker/operators/test_docker.py | 56 +++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/airflow/providers/docker/operators/docker.py 
b/airflow/providers/docker/operators/docker.py
index 2802b9aea7..1d5320d120 100644
--- a/airflow/providers/docker/operators/docker.py
+++ b/airflow/providers/docker/operators/docker.py
@@ -44,6 +44,7 @@ from airflow.providers.docker.exceptions import (
     DockerContainerFailedSkipException,
 )
 from airflow.providers.docker.hooks.docker import DockerHook
+from airflow.utils.types import NOTSET, ArgNotSet
 
 if TYPE_CHECKING:
     from docker import APIClient
@@ -240,9 +241,11 @@ class DockerOperator(BaseOperator):
         skip_on_exit_code: int | Container[int] | None = None,
         port_bindings: dict | None = None,
         ulimits: list[Ulimit] | None = None,
+        # deprecated, no need to include into docstring
+        skip_exit_code: int | Container[int] | ArgNotSet = NOTSET,
         **kwargs,
     ) -> None:
-        if skip_exit_code := kwargs.pop("skip_exit_code", None):
+        if skip_exit_code is not NOTSET:
             warnings.warn(
                 "`skip_exit_code` is deprecated and will be removed in the 
future. "
                 "Please use `skip_on_exit_code` instead.",
@@ -255,7 +258,7 @@ class DockerOperator(BaseOperator):
                     f"skip_on_exit_code={skip_on_exit_code!r}, 
skip_exit_code={skip_exit_code!r}."
                 )
                 raise ValueError(msg)
-            skip_on_exit_code = skip_exit_code
+            skip_on_exit_code = skip_exit_code  # type: ignore[assignment]
         if isinstance(auto_remove, bool):
             warnings.warn(
                 "bool value for `auto_remove` is deprecated and will be 
removed in the future. "
diff --git a/tests/providers/docker/operators/test_docker.py 
b/tests/providers/docker/operators/test_docker.py
index 943ff24eb9..6b4d196ad5 100644
--- a/tests/providers/docker/operators/test_docker.py
+++ b/tests/providers/docker/operators/test_docker.py
@@ -29,6 +29,7 @@ from docker.types import DeviceRequest, LogConfig, Mount, 
Ulimit
 from airflow.exceptions import AirflowException, 
AirflowProviderDeprecationWarning, AirflowSkipException
 from airflow.providers.docker.exceptions import DockerContainerFailedException
 from airflow.providers.docker.operators.docker import DockerOperator
+from airflow.utils.task_instance_session import 
set_current_task_instance_session
 
 TEST_CONN_ID = "docker_test_connection"
 TEST_DOCKER_URL = "unix://var/run/docker.test.sock"
@@ -807,3 +808,58 @@ class TestDockerOperator:
         monkeypatch.delenv("DOCKER_HOST", raising=False)
         operator = DockerOperator(task_id="test", image="test")
         assert operator.docker_url == "unix://var/run/docker.sock"
+
+    @pytest.mark.db_test
+    @pytest.mark.parametrize(
+        "skip_exit_code, skip_on_exit_code, expected",
+        [
+            pytest.param(101, None, [101], id="skip-on-exit-code-not-set"),
+            pytest.param(102, 102, [102], id="skip-on-exit-code-same"),
+        ],
+    )
+    def test_partial_deprecated_skip_exit_code(
+        self, skip_exit_code, skip_on_exit_code, expected, dag_maker, session
+    ):
+        with dag_maker(dag_id="test_partial_deprecated_skip_exit_code", 
session=session):
+            DockerOperator.partial(
+                task_id="fake-task-id",
+                skip_exit_code=skip_exit_code,
+                skip_on_exit_code=skip_on_exit_code,
+            ).expand(image=["test", "apache/airflow"])
+
+        dr = dag_maker.create_dagrun()
+        tis = dr.get_task_instances(session=session)
+        with set_current_task_instance_session(session=session):
+            warning_match = r"`skip_exit_code` is deprecated and will be 
removed"
+            for ti in tis:
+                with pytest.warns(AirflowProviderDeprecationWarning, 
match=warning_match):
+                    ti.render_templates()
+                assert ti.task.skip_on_exit_code == expected
+
+    @pytest.mark.db_test
+    @pytest.mark.parametrize(
+        "skip_exit_code, skip_on_exit_code",
+        [
+            pytest.param(103, 0, id="skip-on-exit-code-zero"),
+            pytest.param(104, 105, id="skip-on-exit-code-not-same"),
+        ],
+    )
+    def test_partial_deprecated_skip_exit_code_ambiguous(
+        self, skip_exit_code, skip_on_exit_code, dag_maker, session
+    ):
+        with dag_maker("test_partial_deprecated_skip_exit_code_ambiguous", 
session=session):
+            DockerOperator.partial(
+                task_id="fake-task-id",
+                skip_exit_code=skip_exit_code,
+                skip_on_exit_code=skip_on_exit_code,
+            ).expand(image=["test", "apache/airflow"])
+
+        dr = dag_maker.create_dagrun(session=session)
+        tis = dr.get_task_instances(session=session)
+        with set_current_task_instance_session(session=session):
+            warning_match = r"`skip_exit_code` is deprecated and will be 
removed"
+            for ti in tis:
+                with pytest.warns(AirflowProviderDeprecationWarning, 
match=warning_match), pytest.raises(
+                    ValueError, match="Conflicting `skip_on_exit_code` 
provided"
+                ):
+                    ti.render_templates()

Reply via email to