ephraimbuddy commented on pull request #16823:
URL: https://github.com/apache/airflow/pull/16823#issuecomment-875037822


   > Can you explain _why_ this is desirable behaviour?
   > 
   > Doesn't returning a dictionary (and setting multiple outputs?) already set 
different xcom keys, or am I making that up?
   
   It does set different xcom keys for 'each' key in the dictionary and at the 
end, the whole dictionary is also set with `return_value` as key. 
   
   What I want in this case, is to change this 'return_value' key that's 
outputted which we don't have control over.
   Take, for example, a python operator task that pushes xcom by returning a 
value.:
   
   ```
   def push_xcom(ti):
       return [3,4,5,6]
   
    task1 = PythonOperator(
           task_id="push_xcom",
           python_callable=push_xcom,
       )
   ```
   Here, we can't change the  key for the xcom pushed, the only way to do it is 
use 
   
   ```
   def push_xcom(ti):
       ti.xcom_push(key='mykey', value=[3,4,5,6])
   ```
   
   And in task decorator we can't change the xcom key used for this function :
   ```
   @task()
   def push_xcom(ti):
       return [3,4,5,6]
   ```
   If we use multiple_outputs and do something like:
   ```
   @task(multiple_outputs=True)
   def push_xcom(ti):
       return {'mykey':[3,4,5,6]}
   ```
   Then Xcoms pushed will be 
   ```
   key=mykey, value=[3,4,5,6]
   key=return_value, value={'mykey':[3,4,56]}
   ```
   With this change, if we have:
   ```
   @task(xcom_key='mykey')
   def push_xcom(ti):
       return [3,4,5,6]
   ```
   Xcom pushed will just be:
   ```
   key=mykey, value=[3,4,5,6]
   ```
   Which is mostly what anyone wants


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