ashb commented on a change in pull request #16866:
URL: https://github.com/apache/airflow/pull/16866#discussion_r690211128
##########
File path: airflow/example_dags/example_xcom.py
##########
@@ -18,50 +18,76 @@
"""Example DAG demonstrating the usage of XComs."""
from airflow import DAG
-from airflow.operators.python import PythonOperator
+from airflow.decorators import task
+from airflow.operators.python import PythonOperator, get_current_context
from airflow.utils.dates import days_ago
value_1 = [1, 2, 3]
value_2 = {'a': 'b'}
+value_3 = 'some value'
def push(**kwargs):
"""Pushes an XCom without a specific target"""
kwargs['ti'].xcom_push(key='value from pusher 1', value=value_1)
+@task
+def push_with_taskflow(val=value_2):
+ """
+ Pushes an XCom from within a task-decorated function aka using the
Taskflow API.
+
+ .. note::
+ Retrieving the current execution context using the
``get_current_context()`` method should only be
+ done when using the Taskflow API.
+ """
+
+ context = get_current_context()
+ context['ti'].xcom_push(key='other value from pusher 1', value=val)
Review comment:
No, this is wrong, and I think this much simpler way will work:
```suggestion
@task
def push_with_taskflow(ti, val=value_2):
"""
Pushes an XCom from within a task-decorated function aka using the
Taskflow API.
"""
ti.xcom_push(key='other value from pusher 1', value=val)
```
(But could you test it please)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]