Skip to content

XCom not working when xcom_pull from subdag task in main DAG #27785

@ana-carolina-januario

Description

@ana-carolina-januario

Apache Airflow version

2.4.3

What happened

I have a DAG with a SubDAGOperator task that has two PythonOperator tasks. Both of the subdag's tasks return values and publish them into xcom. I confirmed and the values are available in XCom List (throught UI).
When inside the subdag I can read the returned values(throught xcom) from one task to the other task.
In the main DAG, the downstream task follow the subdagOperator task needs to pull from xcom the value returned by one of the subdag's task. This is the part that fails: a task from the main DAG can't read the xcom from the subdag tasks.

I've tested reading the xcom using BashOperator and PythonOperator.

I am using python 3.10.8 and Airflow 2.4.3

What you think should happen instead

Using the code:

command = 'echo The returned_value xcom is {{ task_instance.xcom_pull(' \
              'task_ids="push_xcom_value", ' \
              f'dag_id="{DAG_NAME}.{SUB_DAG_NAME}"' \
              ')}}'
    read_xcom_bash = BashOperator(
        task_id="bash_pull",
        bash_command=command,
        do_xcom_push=False,
        dag=dag
    )

for the reader task, we should be able to get the values from xcom.

How to reproduce

I copied the code from airflow's repository examples from xcom usage example and the subdag usage example. the specific bash command used to reproduce the issue is:

command = 'echo The returned_value xcom is {{ task_instance.xcom_pull(' \
              'task_ids="push_xcom_value", ' \
              f'dag_id="{DAG_NAME}.{SUB_DAG_NAME}"' \
              ')}}'
    read_xcom_bash = BashOperator(
        task_id="bash_pull",
        bash_command=command,
        do_xcom_push=False,
        dag=dag
    )

Operating System

Debian GNU/Linux 11 (bullseye)

Versions of Apache Airflow Providers

apache-airflow-providers-amazon==6.0.0
apache-airflow-providers-celery==3.0.0
apache-airflow-providers-cncf-kubernetes==4.4.0
apache-airflow-providers-common-sql==1.2.0
apache-airflow-providers-docker==3.2.0
apache-airflow-providers-elasticsearch==4.2.1
apache-airflow-providers-ftp==3.1.0
apache-airflow-providers-google==8.4.0
apache-airflow-providers-grpc==3.0.0
apache-airflow-providers-hashicorp==3.1.0
apache-airflow-providers-http==4.0.0
apache-airflow-providers-imap==3.0.0
apache-airflow-providers-jdbc==3.2.1
apache-airflow-providers-microsoft-azure==4.3.0
apache-airflow-providers-mysql==3.2.1
apache-airflow-providers-odbc==3.1.2
apache-airflow-providers-postgres==5.2.2
apache-airflow-providers-redis==3.0.0
apache-airflow-providers-sendgrid==3.0.0
apache-airflow-providers-sftp==4.1.0
apache-airflow-providers-slack==6.0.0
apache-airflow-providers-sqlite==3.2.1
apache-airflow-providers-ssh==3.2.0

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

Anything else

It occurs every time.
My team and I need this urgently.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions