This is an automated email from the ASF dual-hosted git repository.
vatsrahul1001 pushed a commit to branch v3-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-4-test by this push:
new 2624b1771d5 [v3-4-test] Preserve explicit falsy partial() values on
mapped operators (#75679) (#77819)
2624b1771d5 is described below
commit 2624b1771d5c7e6361c691458f1ef5ce3741dff6
Author: Rahul Vats <[email protected]>
AuthorDate: Tue Dec 1 13:40:01 2026 +0530
[v3-4-test] Preserve explicit falsy partial() values on mapped operators
(#75679) (#77819)
When [core] default_task_retries is non-zero,
Op.partial(retries=0).expand(...)
serialized without retries, so the scheduler filled it from client_defaults
and the task retried default_task_retries times. The explicit-override check
added in #57853 looked at DAG default_args and constructor kwargs, but
mapped
operators keep explicit values in partial_kwargs.
(cherry picked from commit 37ab48778c9cce8abca6ff6b5e0a61234c1377aa)
Co-authored-by: Aboulfoul <[email protected]>
Co-authored-by: Claude <[email protected]>
---
.../airflow/serialization/serialized_objects.py | 4 ++++
.../unit/serialization/test_dag_serialization.py | 25 ++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/airflow-core/src/airflow/serialization/serialized_objects.py
b/airflow-core/src/airflow/serialization/serialized_objects.py
index f679f23a3ee..a0250ff8886 100644
--- a/airflow-core/src/airflow/serialization/serialized_objects.py
+++ b/airflow-core/src/airflow/serialization/serialized_objects.py
@@ -1501,6 +1501,10 @@ class OperatorSerialization(DAGNode, BaseSerialization):
and op._BaseOperator__init_kwargs[attrname] == var
):
return False
+ # Mapped operators carry explicit values in
partial_kwargs, not __init_kwargs.
+ partial_kwargs = getattr(op, "partial_kwargs", None)
+ if partial_kwargs and attrname in partial_kwargs and
partial_kwargs[attrname] == var:
+ return False
# If client_defaults doesn't have this field (matches schema
default),
# exclude for optimization even if in default_args
diff --git a/airflow-core/tests/unit/serialization/test_dag_serialization.py
b/airflow-core/tests/unit/serialization/test_dag_serialization.py
index bd0f40603c6..7aecac781ef 100644
--- a/airflow-core/tests/unit/serialization/test_dag_serialization.py
+++ b/airflow-core/tests/unit/serialization/test_dag_serialization.py
@@ -4983,6 +4983,31 @@ class TestMappedOperatorSerializationAndClientDefaults:
# Explicit values should override client_defaults
assert deserialized_task.retries == 5 # Explicitly set value
+ @pytest.mark.parametrize(
+ ("default_args", "partial_retries", "expected_retries"),
+ [
+ pytest.param({}, 0, 0, id="partial-zero"),
+ pytest.param({"retries": 1}, 0, 0,
id="partial-zero-overrides-default-args"),
+ pytest.param({}, None, 3, id="unset-uses-client-default"),
+ ],
+ )
+ def test_mapped_operator_preserves_explicit_schema_default(
+ self, default_args, partial_retries, expected_retries,
operator_defaults
+ ):
+ """An explicit partial() value equal to the schema default must
survive when client_defaults differ."""
+ partial_kwargs = {} if partial_retries is None else {"retries":
partial_retries}
+ with operator_defaults({"retries": 3}):
+ with DAG(dag_id="test_mapped_explicit_schema_default",
default_args=default_args) as dag:
+ BashOperator.partial(task_id="mapped_task",
**partial_kwargs).expand(
+ bash_command=["echo 1", "echo 2"]
+ )
+
+ serialized = DagSerialization.to_dict(dag)
+ assert serialized["client_defaults"]["tasks"]["retries"] == 3
+
+ deserialized_task =
DagSerialization.from_dict(serialized).get_task("mapped_task")
+ assert deserialized_task.retries == expected_retries
+
@pytest.mark.parametrize(
("task_config", "dag_id", "task_id", "non_default_fields"),
[