This is an automated email from the ASF dual-hosted git repository.
jscheffl 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 d96ff621ae5 Fix finally return handling (#58998)
d96ff621ae5 is described below
commit d96ff621ae55feff337ca161de295f9d4fa02323
Author: AutomationDev85 <[email protected]>
AuthorDate: Sun Dec 7 23:26:23 2025 +0100
Fix finally return handling (#58998)
Co-authored-by: AutomationDev85 <AutomationDev85>
---
.../src/airflow/providers/cncf/kubernetes/operators/pod.py | 5 +++--
.../tests/unit/cncf/kubernetes/operators/test_pod.py | 10 +++++++---
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git
a/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py
b/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py
index 08182a32d5d..41a331cd24c 100644
---
a/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py
+++
b/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py
@@ -937,8 +937,9 @@ class KubernetesPodOperator(BaseOperator):
raise
finally:
self._clean(event=event, context=context,
result=xcom_sidecar_output)
- if self.do_xcom_push:
- return xcom_sidecar_output
+
+ if self.do_xcom_push and xcom_sidecar_output:
+ context["ti"].xcom_push(XCOM_RETURN_KEY, xcom_sidecar_output)
def _clean(self, event: dict[str, Any], result: dict | None, context:
Context) -> None:
if self.pod is None:
diff --git
a/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py
b/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py
index 91069375b8d..e5e19da79ff 100644
--- a/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py
+++ b/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py
@@ -44,6 +44,7 @@ from airflow.providers.cncf.kubernetes.secret import Secret
from airflow.providers.cncf.kubernetes.triggers.pod import KubernetesPodTrigger
from airflow.providers.cncf.kubernetes.utils.pod_manager import
OnFinishAction, PodLoggingStatus, PodPhase
from airflow.providers.cncf.kubernetes.utils.xcom_sidecar import PodDefaults
+from airflow.providers.common.compat.sdk import XCOM_RETURN_KEY
from airflow.utils import timezone
from airflow.utils.session import create_session
from airflow.utils.types import DagRunType
@@ -1734,7 +1735,7 @@ class TestKubernetesPodOperator:
with pytest.raises(AirflowException):
k.execute(context=context)
- context["ti"].xcom_push.assert_called_with("return_value", {"Test
key": "Test value"})
+ context["ti"].xcom_push.assert_called_with(XCOM_RETURN_KEY, {"Test
key": "Test value"})
@pytest.mark.asyncio
@pytest.mark.parametrize(
@@ -2797,7 +2798,10 @@ def
test_async_kpo_wait_termination_before_cleanup_on_success(
}
k = KubernetesPodOperator(task_id="task", deferrable=True,
do_xcom_push=do_xcom_push)
- result = k.trigger_reentry({}, success_event)
+ context = create_context(k)
+ context["ti"].xcom_push = MagicMock()
+
+ result = k.trigger_reentry(context, success_event)
# check if it gets the pod
mocked_hook.return_value.get_pod.assert_called_once_with(TEST_NAME,
TEST_NAMESPACE)
@@ -2805,7 +2809,7 @@ def
test_async_kpo_wait_termination_before_cleanup_on_success(
# assert that the xcom are extracted/not extracted
if do_xcom_push:
mock_extract_xcom.assert_called_once()
- assert result == mock_extract_xcom.return_value
+ context["ti"].xcom_push.assert_called_with(XCOM_RETURN_KEY,
mock_extract_xcom.return_value)
else:
mock_extract_xcom.assert_not_called()
assert result is None