ashb commented on a change in pull request #16866:
URL: https://github.com/apache/airflow/pull/16866#discussion_r684235887



##########
File path: airflow/example_dags/example_xcom.py
##########
@@ -18,50 +18,61 @@
 
 """Example DAG demonstrating the usage of XComs."""
 from airflow import DAG
-from airflow.operators.python import PythonOperator
+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"""
+
+    # Using the "classic" approach
     kwargs['ti'].xcom_push(key='value from pusher 1', value=value_1)
 
+    # Using the approach available as of Airflow 2.0.  When using this 
approach, `**kwargs`
+    # is not needed to access the execution context.
+    context = get_current_context()
+    context['ti'].xcom_push(key='other value from pusher 1', value=value_2)

Review comment:
       I'm not really sure we need to show `get_current_context()` in example 
DAGs at all -- this feels like an anti-pattern here or an advanced use thing 
only, and people copy examples more than we might like.




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