Fix new DAG versions from serializing a retry_policy object#69243
Merged
Conversation
A mapped operator keeps retry_policy in partial_kwargs, but the mapped-operator serializer has no serializer for a RetryPolicy, so it fell back to str(obj) -- embedding the object's per-process memory address. That made the serialized DAG non-deterministic: dag_hash changed on every parse, defeating write_dag's "unchanged" check and creating a new DagVersion on nearly every DAG-processor re-serialization (even for idle, never-run DAGs), polluting version history and bloating the metadata DB. Non-mapped operators already avoid this by excluding the object and storing only a has_retry_policy flag; this makes the mapped path do the same. Runtime is unaffected -- the worker re-parses the DAG source for the live policy.
kaxil
reviewed
Jul 2, 2026
A RetryPolicy set via DAG default_args hit the same str(obj) fallback as the mapped-operator case, embedding a memory address and producing a new DagVersion on every parse. Route both the mapped partial_kwargs loop and the default_args cleanup through a shared has-flag set (callbacks + retry_policy) so the object is never serialized on either path.
phanikumv
reviewed
Jul 3, 2026
phanikumv
approved these changes
Jul 3, 2026
Mapped operators resolve has_retry_policy through _get_partial_kwargs_or_operator_default (falling back to SerializedBaseOperator's default) rather than the dataclass default, so the false case warrants its own test alongside the existing non-mapped one.
kaxil
reviewed
Jul 3, 2026
kaxil
reviewed
Jul 3, 2026
kaxil
reviewed
Jul 3, 2026
kaxil
reviewed
Jul 3, 2026
kaxil
reviewed
Jul 3, 2026
kaxil
approved these changes
Jul 3, 2026
kaxil
left a comment
Member
There was a problem hiding this comment.
Few non-blocking comments but lgtm otherwise
Review follow-ups: move the retry_policy imports to module top (no collision, unlike the SDK DAG import which stays local), shrink the has-flag branch comment to point at _HAS_FLAG_FIELDS, and assert the positive side (has_retry_policy written, retry_policy stripped) in the default_args test.
Contributor
Backport successfully created: v3-3-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
vatsrahul1001
added a commit
that referenced
this pull request
Jul 3, 2026
…ct (#69243) (#69315) * Fix non-deterministic serialization of mapped task retry_policy A mapped operator keeps retry_policy in partial_kwargs, but the mapped-operator serializer has no serializer for a RetryPolicy, so it fell back to str(obj) -- embedding the object's per-process memory address. That made the serialized DAG non-deterministic: dag_hash changed on every parse, defeating write_dag's "unchanged" check and creating a new DagVersion on nearly every DAG-processor re-serialization (even for idle, never-run DAGs), polluting version history and bloating the metadata DB. Non-mapped operators already avoid this by excluding the object and storing only a has_retry_policy flag; this makes the mapped path do the same. Runtime is unaffected -- the worker re-parses the DAG source for the live policy. * Also strip retry_policy from DAG default_args serialization A RetryPolicy set via DAG default_args hit the same str(obj) fallback as the mapped-operator case, embedding a memory address and producing a new DagVersion on every parse. Route both the mapped partial_kwargs loop and the default_args cleanup through a shared has-flag set (callbacks + retry_policy) so the object is never serialized on either path. * Add negative test for mapped task without a retry_policy Mapped operators resolve has_retry_policy through _get_partial_kwargs_or_operator_default (falling back to SerializedBaseOperator's default) rather than the dataclass default, so the false case warrants its own test alongside the existing non-mapped one. * Hoist retry_policy test imports and assert default_args has_retry_policy Review follow-ups: move the retry_policy imports to module top (no collision, unlike the SDK DAG import which stays local), shrink the has-flag branch comment to point at _HAS_FLAG_FIELDS, and assert the positive side (has_retry_policy written, retry_policy stripped) in the default_args test. (cherry picked from commit b56771c) Co-authored-by: Rahul Vats <43964496+vatsrahul1001@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
A mapped task that uses a retry policy (
.partial(retry_policy=…).expand(…)or@task(retry_policy=…).expand(…)) gets a new DAG version created on nearly everyDAG-processor re-serialization (~30s) — even when the DAG is idle and never run —
spamming the DAG version history and bloating the metadata DB (
dag_version/serialized_dag).Root cause
A mapped operator keeps
retry_policyinpartial_kwargs, and the mapped-operatorserializer has no serializer for a
RetryPolicy, so it falls back tostr(obj)—"<…ExceptionRetryPolicy object at 0x…>". That memory address changes on every parse,so
dag_hashchanges each time, defeatingwrite_dag's "unchanged" check and creatinga new
DagVersionon every re-serialization. Non-mapped operators already avoid this byexcluding the object and storing only a
has_retry_policyflag.Fix
Mirror the non-mapped path in the mapped-operator serializer: don't serialize the object,
store only a
has_retry_policyflag, and addhas_retry_policytoSerializedMappedOperatorso it round-trips. Runtime is unaffected — the worker re-parses the DAG source for the live
policy, so retries still work.
Testing
Adds regression tests that a mapped task with a
retry_policy(a) serializesdeterministically (identical across parses, no embedded object) and (b) round-trips
has_retry_policy=True. Both fail onmainand pass with the fix.Before
After
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.8) following the guidelines