Skip to content

fix Inconsistent XCom Return Type in Mapped Task Groups with Dynamic …#59104

Open
henry3260 wants to merge 5 commits intoapache:mainfrom
henry3260:fix-Xcom-type
Open

fix Inconsistent XCom Return Type in Mapped Task Groups with Dynamic …#59104
henry3260 wants to merge 5 commits intoapache:mainfrom
henry3260:fix-Xcom-type

Conversation

@henry3260
Copy link
Contributor

closes: #59008


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

Copy link
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

It would be nice to add the corresponding unit tests as well, thanks!

Copy link
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed review, thanks for the fix!

LGTM overall, but we still need some refactor on the test to verify the expected behavior, thanks!

@henry3260 henry3260 force-pushed the fix-Xcom-type branch 6 times, most recently from 5631f70 to d11f843 Compare December 29, 2025 18:04
@henry3260 henry3260 requested a review from uranusjr December 29, 2025 18:56
@henry3260
Copy link
Contributor Author

@jason810496 @uranusjr I've addressed the comments. Please let me know if there's anything else blocking the merge.
Appreciate any comments! :)

Copy link
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Not sure if @uranusjr has any additional comments.

@jason810496 jason810496 requested a review from Lee-W February 3, 2026 03:25
@eladkal eladkal added this to the Airflow 3.1.8 milestone Feb 3, 2026
@eladkal eladkal added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Feb 3, 2026
@AutomationDev85
Copy link
Contributor

Hi all, we hit the same issue with Airflow 3.1.7. I don’t think the changes in this PR are sufficient, though. In RuntimeTaskInstance there’s also a check that returns a single item instead of the list when the XCom list has only one element (see https://github.com/apache/airflow/blob/main/task-sdk/src/airflow/sdk/execution_time/task_runner.py#L392). Shouldn’t that be updated too?

@jscheffl
Copy link
Contributor

Oh, this is stale since a while but something I'd expected basic. @uranusjr can you re-review?

Not sure the other problem in task_runner.py as mentioned above can also be a spearate PR not to delay here further. But see the same inconsistency there as well and needs to be fixed.

@henry3260
Copy link
Contributor Author

Oh, this is stale since a while but something I'd expected basic. @uranusjr can you re-review?

Not sure the other problem in task_runner.py as mentioned above can also be a spearate PR not to delay here further. But see the same inconsistency there as well and needs to be fixed.

yeah, maybe I can open another one to address inconsistent issue mentioned abbove.

@vatsrahul1001
Copy link
Contributor

vatsrahul1001 commented Mar 2, 2026

Oh, this is stale since a while but something I'd expected basic. @uranusjr can you re-review?

Not sure the other problem in task_runner.py as mentioned above can also be a spearate PR not to delay here further. But see the same inconsistency there as well and needs to be fixed.

@uranusjr could you re-review?

@jscheffl
Copy link
Contributor

jscheffl commented Mar 2, 2026

@henry3260 can you adjust to get it into 3.1.8 as a fix?

@vatsrahul1001
Copy link
Contributor

@henry3260 can you adjust to get it into 3.1.8 as a fix?

Yeah @henry3260, planning to cut 3.1.8rc1 soon, appreciate it if you can implement the latest review comments

@henry3260
Copy link
Contributor Author

@henry3260 can you adjust to get it into 3.1.8 as a fix?

Yeah @henry3260, planning to cut 3.1.8rc1 soon, appreciate it if you can implement the latest review comments

OK, I will take a look!

@henry3260 henry3260 force-pushed the fix-Xcom-type branch 3 times, most recently from 3490f4f to c026e6a Compare March 3, 2026 13:29
Copilot AI review requested due to automatic review settings March 3, 2026 19:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses inconsistent TaskInstance.xcom_pull() return types for mapped tasks by returning a LazyXComSelectSequence when pulling mapped XComs (map_index >= 0) without explicitly specifying map_indexes, and adds unit tests to validate mapped vs. unmapped behavior.

Changes:

  • Update TaskInstance.xcom_pull() to return LazyXComSelectSequence for mapped XComs when map_indexes is not specified.
  • Add unit tests asserting unmapped pulls return a single deserialized value and mapped pulls return a lazy sequence.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
airflow-core/src/airflow/models/taskinstance.py Adjusts xcom_pull to consistently return a lazy sequence for mapped XComs in the single-task pull path.
airflow-core/tests/unit/models/test_taskinstance.py Adds tests covering unmapped vs. mapped xcom_pull return types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent XCom Return Type in Mapped Task Groups with Dynamic Task Mapping

8 participants