jroachgolf84 opened a new pull request, #51556:
URL: https://github.com/apache/airflow/pull/51556

   #51109 outlined an issue where trying to dynamically map over an XCom return 
value using a custom key. Rather than leveraging the `list` that was stored at 
that key, it would dynamically-map TaskGroups using the key-value pairs in the 
return value itself.
   
   This PR addresses this by applying the same logic present in the 
`_TaskDecorator` class is applied to `_TaskGroupFactory`. When attempting to 
map , the following exception will be raised:
   
   ```
   ValueError: cannot map over XCom with custom key '<key>' from 
<Task(_PythonDecoratedOperator): t>`
   ```
   
   Rather than the faulty logic outlined in #51109, the DAG will fail to parse. 
This matches the same behavior as `@task`. This logic was implemented for both 
`.expand()` and `.expand_kwargs()`.
   
   To test this, the following DAG was written. The result is now a DAG Import 
Error, with the stack trace below.
   
   ``` {python}
   import pendulum
   from airflow.decorators import dag, task, task_group
   
   @dag(schedule=None, start_date=pendulum.datetime(2022, 1, 1))
   def pipeline():
       @task
       def t():
           return {"values": ["value_1", "value_2"]}
   
       @task_group()
       def tg(a, b):
           pass
   
       tg.partial(a=1).expand(b=t()["values"])
   ```
   
   ```
   Traceback (most recent call last):
     File 
"/opt/airflow/task-sdk/src/airflow/sdk/definitions/decorators/task_group.py", 
line 175, in expand_kwargs
       ensure_xcomarg_return_value(expand_input.value)
     File 
"/opt/airflow/task-sdk/src/airflow/sdk/definitions/mappedoperator.py", line 
127, in ensure_xcomarg_return_value
       raise ValueError(f"cannot map over XCom with custom key {key!r} from 
{operator}")
   ValueError: cannot map over XCom with custom key 'targets' from 
<Task(_PythonDecoratedOperator): determine_run_params>
   ```


-- 
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: commits-unsubscr...@airflow.apache.org

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

Reply via email to