How to Stop a Task from Pushing an XCom in Apache Airflow® with do_xcom_push=False
By default, most Apache Airflow® tasks store their result as an XCom, so that another task can use it. A BashOperator stores the last line its command prints, even when no other task needs it. do_xcom_push=False turns that off for one task. This guide compares two BashOperator tasks on Airflow 3.4.0, one with the default and one with do_xcom_push=False.
Syntax
<Operator>(
task_id="<task id>",
<other parameters>,
do_xcom_push=False,
)
| Part | What it means |
|---|---|
<Operator> | Any operator. Every operator has do_xcom_push, because it's a parameter of their common base class, BaseOperator |
do_xcom_push=False | Don't store the task's result as an XCom. The default, True, stores it under the key return_value |
A @task function takes it the same way: @task(do_xcom_push=False).
The BaseOperator reference describes the parameter as "if True, an XCom is pushed containing the Operator’s result". For BashOperator, the result is the last line of output: the BashOperator reference says that with do_xcom_push on, "the last line written to stdout will also be pushed to an XCom when the bash command completes".
The Example
A Dag called bash_xcom has two BashOperator tasks that both run echo "first line"; echo "last line". push_last_line keeps the default, and push_nothing sets do_xcom_push=False.
Prerequisites
- Apache Airflow® running, for example with
airflow standalone, and itsdagsfolder in yourAIRFLOW_HOME.
Step 1: Write the Dag
Create dags/bash_xcom.py:
from airflow.providers.standard.operators.bash import BashOperator
from airflow.sdk import dag
@dag(schedule=None, tags=["demo"])
def bash_xcom():
BashOperator(
task_id="push_last_line",
bash_command='echo "first line"; echo "last line"',
)
BashOperator(
task_id="push_nothing",
bash_command='echo "first line"; echo "last line"',
do_xcom_push=False,
)
bash_xcom()

Both tasks print two lines. The only difference is do_xcom_push=False on push_nothing.
Step 2: See What the Default Stores
Trigger the Dag, then open the push_last_line task and its XCom tab (How to See a Task's XComs in the Apache Airflow® UI shows where to click):

One entry, return_value, with the value last line. The command printed two lines, and only the last one was stored.
Step 3: See That the Other Task Stores Nothing
Click the run's square for push_nothing:

0 XCom Entries and No XCom Entries found: the task ran the same command and succeeded, and stored nothing. In this example's metadata database, the database where Airflow keeps its records, push_last_line had a row in the XCom table and push_nothing had none.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Turning it off on a task whose result another task uses | Nothing fails: the next task gets None. In a check, tasks that read the results of a @task(do_xcom_push=False) function and of a BashOperator with do_xcom_push=False both got None | Keep the default on tasks whose result is passed on |
| Expecting every line of a BashOperator's output in the XCom | Only the last line is stored: last line, not first line | Print the value to pass on last |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
A task gets None from the task before it | The earlier task has do_xcom_push=False | Remove do_xcom_push=False from it |
No XCom Entries found in the XCom tab | The task has do_xcom_push=False, or it returned nothing | Expected if no other task needs its result |
FAQ
When should I turn it off?
When no other task uses the result. XComs "are only designed for small amounts of data", says the XCom documentation, and a BashOperator stores its last line whatever it is. With do_xcom_push=False, nothing is stored.
Does it work with @task?
Yes. @task(do_xcom_push=False) on a function that returned 5 stored no XCom.
Conclusion
With the default, push_last_line stored its command's last line, last line, under return_value. With do_xcom_push=False, push_nothing ran the same command and stored nothing. Turn it off only on tasks whose result no other task needs, because a task that reads it gets None.
Additional Resources
- XComs —
return_valueanddo_xcom_push. - BashOperator reference — what a BashOperator stores.
BaseOperatorreference —do_xcom_pushand the other parameters every operator has.
Apache®, Apache Airflow and Airflow® are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.
