Skip to content

Fix misleading type errors from expand_kwargs and default_args - #73120

Closed
Eason09053360 wants to merge 1 commit into
apache:mainfrom
Eason09053360:fix-wrong-variable-in-type-error-messages
Closed

Eason09053360 wants to merge 1 commit into
apache:mainfrom
Eason09053360:fix-wrong-variable-in-type-error-messages

Conversation

@Eason09053360

Copy link
Copy Markdown
Contributor

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:

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:

# 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 Sequences 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?
  • Yes — Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5) following the guidelines

Someone who puts a bad element in an expand_kwargs list was told the
container's type ("not list"), which contradicts the expected type in the
same sentence and says nothing about the element that was actually
rejected. Someone who passes a bad default_args was told the type of
task_params instead -- often ParamsDict, an internal wrapper they never
supplied, or NoneType when they passed no params at all.

Both messages send a person debugging towards a value that is not the
problem. Reporting the rejected value alongside the container keeps
everything the old message carried, so no input is described with less
detail than before.
@potiuk

potiuk commented Sep 25, 2026

Copy link
Copy Markdown
Member

Hello @Eason09053360 - thank you for your contributions to Apache Airflow!

The Airflow community has introduced a limit of 5 open pull requests at a time for contributors without write access to the repository. You currently have 33 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:

These pull requests stay open because maintainers are already engaged in them - they count towards your limit:

This is not a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are.

What we ask you to do is to make your first prioritization decision: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or gh pr reopen <PR_NUMBER> --repo apache/airflow. Reopen the ones you are ready to follow through - keep them rebased, respond to review comments and fix failing checks.

While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack.

Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:task-sdk closed because of open PR limit Closed as a one-time step of introducing the open pull request limit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants