|
38 | 38 | ListOfDictsExpandInput, |
39 | 39 | MappedArgument, |
40 | 40 | ) |
| 41 | +from airflow.models.mappedoperator import ensure_xcomarg_return_value |
41 | 42 | from airflow.models.taskmixin import DAGNode |
42 | 43 | from airflow.models.xcom_arg import XComArg |
43 | 44 | from airflow.typing_compat import ParamSpec |
@@ -134,6 +135,11 @@ def expand(self, **kwargs: OperatorExpandArgument) -> DAGNode: |
134 | 135 | self._validate_arg_names("expand", kwargs) |
135 | 136 | prevent_duplicates(self.partial_kwargs, kwargs, fail_reason="mapping already partial") |
136 | 137 | expand_input = DictOfListsExpandInput(kwargs) |
| 138 | + |
| 139 | + # Similar to @task, @task_group should not be "mappable" over an XCom with a custom key. This will |
| 140 | + # raise an exception, rather than having an ambiguous exception similar to the one found in #51109. |
| 141 | + ensure_xcomarg_return_value(expand_input.value) |
| 142 | + |
137 | 143 | return self._create_task_group( |
138 | 144 | functools.partial(MappedTaskGroup, expand_input=expand_input), |
139 | 145 | **self.partial_kwargs, |
@@ -163,6 +169,11 @@ def expand_kwargs(self, kwargs: OperatorExpandKwargsArgument) -> DAGNode: |
163 | 169 | map_kwargs = (k for k in self.function_signature.parameters if k not in self.partial_kwargs) |
164 | 170 |
|
165 | 171 | expand_input = ListOfDictsExpandInput(kwargs) |
| 172 | + |
| 173 | + # Similar to @task, @task_group should not be "mappable" over an XCom with a custom key. This will |
| 174 | + # raise an exception, rather than having an ambiguous exception similar to the one found in #51109. |
| 175 | + ensure_xcomarg_return_value(expand_input.value) |
| 176 | + |
166 | 177 | return self._create_task_group( |
167 | 178 | functools.partial(MappedTaskGroup, expand_input=expand_input), |
168 | 179 | **self.partial_kwargs, |
|
0 commit comments