Skip to content

Conversation

@amoghrajesh
Copy link
Contributor

@amoghrajesh amoghrajesh commented Jul 28, 2025

closes: #53593

Problem

The include_prior_dates parameter in xcom_pull() was being completely ignored when map_indexes was not explicitly specified (default NOTSET case). This caused XComs from previous DAG runs to not be retrieved even when include_prior_dates=True was passed.

Example:

@task def xcom_task(ti): # This should find XComs from previous runs, but didn't work data_xcom = ti.xcom_pull(key="test_key", include_prior_dates=True) if data_xcom: print(f'XCom pulled. Value: {data_xcom}') else: print(f'XCom not found') # Always printed this, even when XCom existed from previous run ti.xcom_push(key="test_key", value=' - xcom value - ') 

Expected behavior: 2nd run should print "XCom pulled. Value: - xcom value -"

Why?

After #51568, the xcom_pull() method has with two code paths:

  • When map_indexes=NOTSET → use XCom.get_all() to get all the xcoms for all map indexes
  • When map_indexes explicitly specified → use XCom.get_one()

After introducing path 1, there could be cases when include_prior_dates is passed but XCom.get_all path is chosen, which ignores that parameter entirely.

The bug occurred because:
XCom.get_all() didn't support the include_prior_dates parameter
The first path was always chosen when map_indexes wasn't specified
include_prior_dates was silently ignored and never passed through the communication chain

Solution

Extended the first path to support include_prior_dates by threading the parameter through the entire communication chain:

  • XCom.get_all() - Added include_prior_dates: bool = False parameter
  • GetXComSequenceSlice - Added include_prior_dates: bool = False field
  • Supervisor - Updated to pass include_prior_dates to API client
  • API Client - Updated get_sequence_slice() to accept and pass parameter
  • API Server - Updated get_mapped_xcom_by_slice() to use parameter in database query
  • Task Runner - Updated to pass include_prior_dates to XCom.get_all()

Testing

DAG:
Min repro dag from the issue:

from datetime import datetime, timedelta from airflow.sdk import dag, task @dag( schedule=timedelta(seconds=60), start_date=datetime(2025, 7, 22), catchup=False, max_active_runs=1 ) def xcom_test(): @task def xcom_task(ti): data_xcom = ti.xcom_pull(key=f"test_key", include_prior_dates=True) if data_xcom: print(f'XCom pulled. Value: {data_xcom}') else: print(f'XCom not found') ti.xcom_push(key=f"test_key", value=' - xcom value - ') xcom_task() xcom_test() 

Before

Run 1:

image

Run 2 and later:
image

After

Run 1:

image

Run 2:

image

Run 3:

image

No Cadywn migration needed - This is a backward compatible API change with change only in parameters and no request / response models have changed.


^ 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.

@amoghrajesh amoghrajesh requested review from ashb and kaxil as code owners July 28, 2025 09:54
@boring-cyborg boring-cyborg bot added area:API Airflow's REST/HTTP API area:task-sdk labels Jul 28, 2025
@amoghrajesh amoghrajesh requested a review from uranusjr July 28, 2025 10:01
@amoghrajesh amoghrajesh self-assigned this Jul 28, 2025
@amoghrajesh amoghrajesh requested a review from kaxil July 28, 2025 15:06
@amoghrajesh amoghrajesh added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Jul 29, 2025
@amoghrajesh amoghrajesh added this to the Airflow 3.0.4 milestone Jul 29, 2025
@amoghrajesh amoghrajesh merged commit 2a2d3e1 into apache:main Jul 29, 2025
196 of 197 checks passed
@amoghrajesh amoghrajesh deleted the xcom-prior-dates branch July 29, 2025 05:04
@github-actions
Copy link

Backport failed to create: v3-0-test. View the failure log Run details

Status Branch Result
v3-0-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 2a2d3e1 v3-0-test

This should apply the commit to the v3-0-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue
@amoghrajesh
Copy link
Contributor Author

This likely needs multiple other PRs to be cherry picked

RoyLee1224 pushed a commit to RoyLee1224/airflow that referenced this pull request Jul 31, 2025
ferruzzi pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Aug 7, 2025
@ashb ashb modified the milestones: Airflow 3.0.4, Airflow 3.0.5 Aug 8, 2025
amoghrajesh added a commit to astronomer/airflow that referenced this pull request Aug 11, 2025
fweilun pushed a commit to fweilun/airflow that referenced this pull request Aug 11, 2025
amoghrajesh added a commit to astronomer/airflow that referenced this pull request Aug 11, 2025
amoghrajesh added a commit to astronomer/airflow that referenced this pull request Aug 11, 2025
amoghrajesh added a commit to astronomer/airflow that referenced this pull request Aug 11, 2025
kaxil pushed a commit that referenced this pull request Aug 11, 2025
kaxil added a commit to astronomer/airflow that referenced this pull request Aug 22, 2025
Extend `AddIncludePriorDatesToGetXComSlice` version change to include `GetXcomFilterParams` in addition to `GetXComSliceFilterParams`. This ensures that the include_prior_dates field is properly handled in API version migrations for both XCom endpoints: - GET /xcoms/{dag_id}/{run_id}/{task_id}/{key} (single XCom) - GET /xcoms/{dag_id}/{run_id}/{task_id}/{key}/slice (XCom slice) This was missed in apache#53809
kaxil added a commit to astronomer/airflow that referenced this pull request Aug 22, 2025
Extend `AddIncludePriorDatesToGetXComSlice` version change to include `GetXcomFilterParams` in addition to `GetXComSliceFilterParams`. This ensures that the include_prior_dates field is properly handled in API version migrations for both XCom endpoints: - GET /xcoms/{dag_id}/{run_id}/{task_id}/{key} (single XCom) - GET /xcoms/{dag_id}/{run_id}/{task_id}/{key}/slice (XCom slice) This was missed in apache#53809
kaxil added a commit that referenced this pull request Aug 22, 2025
Extend `AddIncludePriorDatesToGetXComSlice` version change to include `GetXcomFilterParams` in addition to `GetXComSliceFilterParams`. This ensures that the include_prior_dates field is properly handled in API version migrations for both XCom endpoints: - GET /xcoms/{dag_id}/{run_id}/{task_id}/{key} (single XCom) - GET /xcoms/{dag_id}/{run_id}/{task_id}/{key}/slice (XCom slice) This was missed in #53809
mangal-vairalkar pushed a commit to mangal-vairalkar/airflow that referenced this pull request Aug 30, 2025
Extend `AddIncludePriorDatesToGetXComSlice` version change to include `GetXcomFilterParams` in addition to `GetXComSliceFilterParams`. This ensures that the include_prior_dates field is properly handled in API version migrations for both XCom endpoints: - GET /xcoms/{dag_id}/{run_id}/{task_id}/{key} (single XCom) - GET /xcoms/{dag_id}/{run_id}/{task_id}/{key}/slice (XCom slice) This was missed in apache#53809
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Oct 24, 2025
Extend `AddIncludePriorDatesToGetXComSlice` version change to include `GetXcomFilterParams` in addition to `GetXComSliceFilterParams`. This ensures that the include_prior_dates field is properly handled in API version migrations for both XCom endpoints: - GET /xcoms/{dag_id}/{run_id}/{task_id}/{key} (single XCom) - GET /xcoms/{dag_id}/{run_id}/{task_id}/{key}/slice (XCom slice) This was missed in apache/airflow#53809 GitOrigin-RevId: 2821393915ddec40b074ebf437014e3f773093c1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:task-sdk backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

4 participants