[v3-3-test] Fix new DAG versions from serializing a retry_policy object (#69243)#69315
Merged
Conversation
…ct (#69243) * 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>
1 task
vatsrahul1001
approved these changes
Jul 3, 2026
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.
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.
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.
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.
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