Skip to content

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

Merged
jscheffl merged 5 commits into
apache:mainfrom
henry3260:fix-Xcom-type
Mar 10, 2026
Merged

fix Inconsistent XCom Return Type in Mapped Task Groups with Dynamic …#59104
jscheffl merged 5 commits into
apache:mainfrom
henry3260:fix-Xcom-type

Conversation

@henry3260

Copy link
Copy Markdown
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.

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

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!

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

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!

Comment thread airflow-core/tests/unit/models/test_taskinstance.py Outdated
Comment thread airflow-core/tests/unit/models/test_taskinstance.py Outdated
Comment thread airflow-core/tests/unit/models/test_taskinstance.py Outdated
Comment thread airflow-core/tests/unit/models/test_taskinstance.py Outdated
Comment thread airflow-core/src/airflow/models/taskinstance.py Outdated
Comment thread airflow-core/src/airflow/models/taskinstance.py Outdated
@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
Copy Markdown
Contributor Author

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

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

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
@AutomationDev85

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

vatsrahul1001 commented Mar 2, 2026

Copy link
Copy Markdown
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.

@uranusjr could you re-review?

Comment thread airflow-core/src/airflow/models/taskinstance.py Outdated
@jscheffl

jscheffl commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

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

@vatsrahul1001

Copy link
Copy Markdown
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
Copy Markdown
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread airflow-core/src/airflow/models/taskinstance.py
Comment thread airflow-core/tests/unit/models/test_taskinstance.py
@henry3260

Copy link
Copy Markdown
Contributor Author

I think this PR is good to go, but let me know if I missed anything.

@jscheffl jscheffl merged commit df2e2b8 into apache:main Mar 10, 2026
72 checks passed
github-actions Bot pushed a commit that referenced this pull request Mar 10, 2026
…ith Dynamic … (#59104)

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

* add unit test for xcom_pull

* remove asc func
(cherry picked from commit df2e2b8)

Co-authored-by: Henry Chen <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-1-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-1-test PR Link

jscheffl pushed a commit that referenced this pull request Mar 10, 2026
…ith Dynamic … (#59104) (#63293)

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

* add unit test for xcom_pull

* remove asc func
(cherry picked from commit df2e2b8)

Co-authored-by: Henry Chen <[email protected]>
dominikhei pushed a commit to dominikhei/airflow that referenced this pull request Mar 11, 2026
apache#59104)

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

* add unit test for xcom_pull

* remove asc func
Pyasma pushed a commit to Pyasma/airflow that referenced this pull request Mar 13, 2026
apache#59104)

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

* add unit test for xcom_pull

* remove asc func
vatsrahul1001 pushed a commit that referenced this pull request Mar 25, 2026
…ith Dynamic … (#59104) (#63293)

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

* add unit test for xcom_pull

* remove asc func
(cherry picked from commit df2e2b8)

Co-authored-by: Henry Chen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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