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/10/26 18:40:32 UTC

[GitHub] [airflow] ephraimbuddy commented on issue #11858: Xcom_pull results order is not deterministic

ephraimbuddy commented on issue #11858:
URL: https://github.com/apache/airflow/issues/11858#issuecomment-716747899


   This example dag below gives inconsistent results:
   
   ```
   #
   # Licensed to the Apache Software Foundation (ASF) under one
   # or more contributor license agreements.  See the NOTICE file
   # distributed with this work for additional information
   # regarding copyright ownership.  The ASF licenses this file
   # to you under the Apache License, Version 2.0 (the
   # "License"); you may not use this file except in compliance
   # with the License.  You may obtain a copy of the License at
   #
   #   http://www.apache.org/licenses/LICENSE-2.0
   #
   # Unless required by applicable law or agreed to in writing,
   # software distributed under the License is distributed on an
   # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   # KIND, either express or implied.  See the License for the
   # specific language governing permissions and limitations
   # under the License.
   
   """Example DAG demonstrating the usage of XComs."""
   from airflow import DAG
   from airflow.operators.python import PythonOperator
   from airflow.utils.dates import days_ago
   
   dag = DAG(
       'example_xcom',
       schedule_interval="@once",
       start_date=days_ago(2),
       default_args={'owner': 'airflow'},
       tags=['example']
   )
   
   value_1 = [1, 2, 3]
   value_2 = {'a': 'b'}
   
   
   def push(**kwargs):
       """Pushes an XCom without a specific target"""
       kwargs['ti'].xcom_push(key='value from pusher 1', value=value_1)
   
   
   def push_by_returning(**kwargs):
       """Pushes an XCom without a specific target, just by returning it"""
       return value_2
   
   
   def puller(**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')
       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}')
       if pulled_value_2 != value_2:
           raise ValueError(f'The two values differ {pulled_value_2} and {value_2}')
   
   
   push1 = PythonOperator(
       task_id='push',
       dag=dag,
       python_callable=push,
   )
   
   push2 = PythonOperator(
       task_id='push_by_returning',
       dag=dag,
       python_callable=push_by_returning,
   )
   
   pull = PythonOperator(
       task_id='puller',
       dag=dag,
       python_callable=puller,
   )
   
   pull << [push1, push2]
   ```
   I checked the code, the xcom_pull are ordered both with execution_date and timestamp.
   However, for the above DAG, the tasks have the same execution_date and may also have the same timestamp. In this case, the order of the xcom_pull result is not consistent.


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