Fix mapped task group XCom collapsing to a bare value for a single expansion#69075
Open
shahar1 wants to merge 2 commits into
Open
Fix mapped task group XCom collapsing to a bare value for a single expansion#69075shahar1 wants to merge 2 commits into
shahar1 wants to merge 2 commits into
Conversation
Closed
2 tasks
cdf92e6 to
2b8c984
Compare
1 task
…pansion A task consuming the output of a mapped task group from outside that group must always receive a list with one element per expansion. Since the task-start upstream map-index computation moved into the Task SDK, an unmapped downstream resolving a task inside a mapped task group fell through to pulling all map indexes via xcom_pull, which collapses a single value to a bare scalar and an empty set of values to None. A group that expanded only once therefore handed the raw value to the downstream task instead of a one-element list, and a group whose expansions all returned None handed None instead of an empty list. The pre-3.2 server returned list(range(mapped_ti_count)) for this case, so the behaviour regressed. Resolve this case by eagerly materialising the group's per-expansion XComs into a list (a single slice request), so the result is always a list regardless of how many times the group expanded or whether every value was None, and stays serializable when a task returns it unchanged.
2b8c984 to
a28c3f0
Compare
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.
closes: #69036
related: #48005
Human Summary
Currently, when
map_indexesis left unset, a single mapped result collapses to its bare value instead of staying one-element list.It started to happen after #60803 was merged, when the upstream map-index computation was relocated to the task-sdk.
This PR fixes it by returning an eagerly-materialized
LazyXComSequenceobject.AI Summary
Click here
A task consuming the output of a mapped task group from **outside** that group must always receive a list with one element per expansion. When the task-start upstream map-index computation moved into the Task SDK (#60803, released in 3.2.0), an unmapped downstream resolving a task inside a mapped task group started falling through to pulling all map indexes via `xcom_pull`, which collapses a single value to a bare scalar and an empty set of values to `None`.As a result:
'14'and iterated'1','4'instead of receiving['14']).Nonewould handNoneinstead of an empty list (the Result of expanded task is None instead of empty list when all mapped tasks return None #48005 class of bug, via the task-group resolution path).This worked correctly in 3.1.5: the pre-3.2 server returned
list(range(mapped_ti_count))for this case, guaranteeing a list. The fix resolves this case through aLazyXComSequence, mirroring how a directly mapped task already resolves, so the result is always a list regardless of how many times the group expanded or whether every value wasNone.Verified end to end with
airflow dags teston the reproduction DAGs from both issues:['14'](was'14'),Nonegroup expansions yield[],Nonecase from Result of expanded task is None instead of empty list when all mapped tasks return None #48005 continues to yield[].Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.8) following the guidelines