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 2020/11/15 22:05:10 UTC

[GitHub] [airflow] turbaszek commented on a change in pull request #12376: Use new syntax for xcom pull in example dags

turbaszek commented on a change in pull request #12376:
URL: https://github.com/apache/airflow/pull/12376#discussion_r523820546



##########
File path: airflow/example_dags/example_xcom.py
##########
@@ -43,24 +44,14 @@ def push_by_returning(**kwargs):
     return value_2
 
 
-def puller(**kwargs):
+def puller(pulled_value_1, pulled_value_2, **kwargs):
     """Pull all previously pushed XComs and check if the pushed values match the pulled values."""
-    ti = kwargs['ti']
 
-    # get value_1
-    pulled_value_1 = ti.xcom_pull(key=None, task_ids='push')
+    # check pulled value 1
     if pulled_value_1 != value_1:
         raise ValueError(f'The two values differ {pulled_value_1} and {value_1}')
 
-    # get value_2
-    pulled_value_2 = ti.xcom_pull(task_ids='push_by_returning')
-    if pulled_value_2 != value_2:
-        raise ValueError(f'The two values differ {pulled_value_2} and {value_2}')
-
-    # get both value_1 and value_2
-    pulled_value_1, pulled_value_2 = ti.xcom_pull(key=None, task_ids=['push', 'push_by_returning'])
-    if pulled_value_1 != value_1:
-        raise ValueError(f'The two values differ {pulled_value_1} and {value_1}')

Review comment:
       I would still keep an example of accessing `ti` from `kwargs` for example:
   ```
   # check pulled value 1
   ...
   # same using explicit xcom pull
   from_xcom = ti.xcom_pull(key=None, task_ids='push')
   if from_xcom != pulled_value_1:
       raise ValueError(f'The two values differ {pulled_value_1} and {value_1}
   ```
   WDYT?




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

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