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

   ## Why
   
   Two `TypeError` messages in the Task SDK name a value that is not the one 
being rejected, so they point a person debugging at the wrong thing.
   
   `expand_kwargs` validates a list element-by-element, but reports the 
container's type:
   
   ```python
   process.expand_kwargs([{"file": "a.csv"}, 5])
   # TypeError: expected XComArg or list[dict], not list
   ```
   
   The list is exactly what `expand_kwargs` wants — the `5` inside it is the 
problem, and the message never mentions it. `git log -S` traces this to #25925, 
which added the element loop by copying the existing `raise` and updating the 
message text but not the `type(kwargs)` in it. The `elif` branch below it, 
where `kwargs` really is the rejected value, was left correct.
   
   `get_merged_defaults` reports `task_params` when it rejects 
`task_default_args`:
   
   ```python
   # with a valid params= argument
   TypeError: default_args must be a mapping, got <class 'ParamsDict'>   # an 
internal wrapper the caller never passed
   # with no params= argument at all
   TypeError: default_args must be a mapping, got <class 'NoneType'>
   ```
   
   Neither message names `list`, which is what the caller actually passed as 
`default_args`.
   
   ## What
   
   - `task-sdk/src/airflow/sdk/bases/operator.py` — `get_merged_defaults` 
reports `task_default_args`.
   - `task-sdk/src/airflow/sdk/bases/decorator.py`, 
`definitions/mappedoperator.py`, `definitions/decorators/task_group.py` — the 
element loop in all three `expand_kwargs` implementations now reports the 
container **and** the element: `not list containing int`.
   
   Reporting both matters because `str` and `bytes` are `Sequence`s and take 
the element loop too. Naming only the element would describe 
`expand_kwargs("abc")` as `not list[str]` and `expand_kwargs(b"ab")` as `not 
list[int]`, both worse than today's `not str` / `not bytes`; `bytearray` and 
`memoryview` behave the same way, so there is no short list of types to 
special-case. Keeping the container type means no input is described with less 
detail than before, and a `tuple` of dicts with one bad element now reads `not 
tuple containing int` instead of the misleading `not tuple`.
   
   These four error paths had no test coverage, which is how the 
`expand_kwargs` slip survived since 2022. Each site gets a parametrized test 
covering the rejected element, the rejected container (guarding the `elif` 
branch that was already correct), and `str`/`bytes`.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Opus 5)
   
   Generated-by: Claude Code (Opus 5) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


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