dabla commented on code in PR #62922:
URL: https://github.com/apache/airflow/pull/62922#discussion_r4743917386
##########
task-sdk/src/airflow/sdk/definitions/_internal/expandinput.py:
##########
@@ -215,12 +433,31 @@ def iter_references(self) -> Iterable[tuple[Operator,
str]]:
if isinstance(x, XComArg):
yield from x.iter_references()
+ async def aresolve(self, context: Mapping[str, Any]) -> Resolved:
+ from airflow.sdk.definitions.xcom_arg import XComArg
+
+ if isinstance(self.value, XComArg):
+ source = await Source.from_argument(self.value, context)
+ else:
+ source = Source(
+ [await item.aresolve(context) if isinstance(item, XComArg)
else item for item in self.value]
+ )
+
+ async def aget(index: int) -> Mapping[str, Any]:
+ mapping = await source.aget(index)
+ if not isinstance(mapping, Mapping):
+ raise ValueError(
+ f"iterate_kwargs() expects a list[dict], not
list[{_describe_type(mapping)}]"
+ )
+ return mapping
Review Comment:
Good catch, thanks. Rather than copying the check, I moved both validations
(a mapping, keys all `str`) into one helper, `_validate_kwargs_mapping(mapping,
call)`, which `expand_kwargs()` in `resolve()` and `iterate_kwargs()` in
`aget()` now both call, so the two can't drift apart again (DRY). The
`expand_kwargs()` messages are unchanged, and a test covers the non-`str` key
for `iterate_kwargs()`. In 7bfec49670.
--
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]