Skip to content

Correct xcom patch API to be usable with tasks #59032

Description

@amoghrajesh

Body

Context: #58900 (comment)

If we use the xcom patch API to perform an update on an XCom via the PATCH API, you wouldn't really get a usable value out in the task.

Ways to repro this:

  1. Define a dag like this:
from datetime import datetime

from airflow.decorators import task
from airflow.models.dag import DAG

with DAG(dag_id="add_dag", schedule=None, start_date=datetime(2022, 3, 4)) as dag:

    @task
    def add_one(x: int):
        return x + 1

    @task
    def add_two(y: int):
        # y is result of add_one
        return y + 1

    @task
    def add_all_past_values(**context):
        xcoms = context['ti'].xcom_pull(task_ids=["add_one", "add_two"], include_prior_dates=True)
        print(xcoms)


    res1 = add_one(1)
    add_two(res1)

    add_all_past_values()
  1. Run the dag a couple times
  2. Identify a past run and update its xcom entry:
curl -X 'PATCH' \
  'http://localhost:28080/api/v2/dags/add_dag/dagRuns/manual__2025-12-02T07%3A34%3A26%2B00%3A00/taskInstances/add_one/xcomEntries/return_value' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "value": 7,
  "map_index": -1
}'
  1. Observe the output
Image

Note the format of 7 from earlier patch, it is excessively serialised

Committer

  • I acknowledge that I am a maintainer/committer of the Apache Airflow project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions