You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/07/05 18:23:11 UTC
[GitHub] [airflow] ephraimbuddy commented on pull request #16823: Add ability to specify XCom key for operators and task decorator
ephraimbuddy commented on pull request #16823:
URL: https://github.com/apache/airflow/pull/16823#issuecomment-874271273
Tested with these two dags:
```
from airflow import DAG
from airflow.utils.dates import days_ago
from airflow.operators.python import PythonOperator
dag = DAG(
"example_xcom",
schedule_interval="@once",
start_date=days_ago(2)
)
def push_xcom(ti):
# returning a value pushes xcom
return [3,4,5,6]
def pull_xcom(ti):
# Pull an xcom
xcom = ti.xcom_pull(task_ids='push_xcom', key='mykey')
print("Xcom pulled: ", xcom)
with dag:
task1 = PythonOperator(
task_id="push_xcom",
python_callable=push_xcom,
xcom_key='mykey',
)
task2 = PythonOperator(
task_id="pull_xcom",
python_callable=pull_xcom
)
task1 >> task2
```
```
from airflow import DAG
from airflow.utils.dates import days_ago
dag = DAG(dag_id="test-xcom-key", schedule_interval="@once", start_date=days_ago(2))
@dag.task(xcom_key="mykey")
def push_xcom():
return {"mydata":[3,4,5,6]}
@dag.task()
def push_another_xcom(data):
print(data)
return {'mydata':"mydata"}
push_another_xcom(push_xcom())
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org