josh-fell commented on a change in pull request #16866:
URL: https://github.com/apache/airflow/pull/16866#discussion_r690843020



##########
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:
   > 
   > (But could you test it please)
   
   Tested this out. Just needed to make `ti` an optional arg -- otherwise DAG 
parsing would throw an exception -- and it worked just fine.  Seems to make the 
use of `get_current_context()` more nebulous.

##########
File path: airflow/example_dags/example_xcom.py
##########
@@ -78,6 +104,14 @@ def puller(**kwargs):
     pull = PythonOperator(
         task_id='puller',
         python_callable=puller,
+        op_kwargs={
+            'pulled_value_1': push1.output['value from pusher 1'],
+            'pulled_value_3': push2.output,
+        },

Review comment:
       Reverted Taskflow API and `get_current_context()` changes in the 
"example_xcom" DAG.




-- 
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-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to