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



##########
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:
       To close the gap on this comment, I've gone ahead and removed any 
TaskFlow API-related changes (reference [this 
comment](https://github.com/apache/airflow/pull/16866#discussion_r689944981)).  
We can discuss later when I tackle another example DAG issue but passing in the 
`ti` object as optional works just fine and I'll incorporate this change then.




-- 
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]


Reply via email to