Clarify task decorator argument errors - #69157
Conversation
shahar1
left a comment
There was a problem hiding this comment.
@deepujain please note that you (or your operator) should include AI attribution in the PR as we state in the AI guidelines.
This PR, as well as others, are blocked from being merged until this is corrected.
Please be warned that creating additional PRs except for the 10 you've already created (listed below) without addressing the above might cause in a permanent block from Apache organization on GitHub.
List of PRs:
2c14d36 to
8ac47bd
Compare
|
Rebased this branch onto current Drafted-by: OpenAI Codex (no human review before posting) |
8ac47bd to
5fdd4b4
Compare
|
The three provider compatibility jobs failed while importing an incompatible Drafted-by: OpenAI Codex (no human review before posting) |
5fdd4b4 to
c9485a7
Compare
|
Rebased onto current Drafted-by: OpenAI Codex (no human review before posting) |
c9485a7 to
a2aa16f
Compare
|
Rebased onto current Drafted-by: OpenAI Codex (no human review before posting) |
a2aa16f to
82016f3
Compare
|
Rebased onto current Drafted-by: OpenAI Codex (no human review before posting) |
|
|
||
|
|
||
| def _should_add_task_decorator_call_hint(err: TypeError, op_args: Collection[Any]) -> bool: | ||
| return bool(op_args) and "too many positional arguments" in str(err) |
There was a problem hiding this comment.
The heuristic is too broad for the hint text it produces. Any direct call like my_task(1, 2, 3) with a plain arity mistake (no shadowing involved at all) hits the exact same TypeError message, which is simply wrong in that case.
There was a problem hiding this comment.
Agreed. I narrowed the check so it inspects the stack only after binding fails and adds the hint only when the underlying callable is already executing. A direct arity mistake such as dummy_task(1, 2) now keeps the original error; Ruff and all three targeted regression tests pass.
Drafted-by: OpenAI Codex (no human review before posting)
82016f3 to
e7e988b
Compare
Title: Clarify task decorator argument errors (#49875)
Summary
Calling a decorated task object like a regular function can raise a bare
TypeError: too many positional arguments, which makes the reported name-shadowing failure hard to diagnose. This keeps the existing binding validation but adds a targeted hint only when the binding failure already happened for extra positional arguments.Changes
task-sdk/src/airflow/sdk/bases/decorator.py-- wrap signature binding errors and append an accidental decorated-task-call hint only for extra positional arguments.task-sdk/tests/task_sdk/bases/test_decorator.py-- add regression coverage for the accidental call case and verify missing required arguments do not receive the hint.airflow-core/newsfragments/69157.bugfix.rst-- add a bugfix release note for the user-facing error-message improvement.Evidence it works
Test plan
uvx --from uv==0.11.21 uv run --project task-sdk ruff format --check task-sdk/src/airflow/sdk/bases/decorator.py task-sdk/tests/task_sdk/bases/test_decorator.pyuvx --from uv==0.11.21 uv run --project task-sdk ruff check task-sdk/src/airflow/sdk/bases/decorator.py task-sdk/tests/task_sdk/bases/test_decorator.pyuvx --from uv==0.11.21 uv run --project task-sdk pytest task-sdk/tests/task_sdk/bases/test_decorator.py::TestDefaultFillingLogic::test_bind_validation_hints_for_accidental_task_decorator_call task-sdk/tests/task_sdk/bases/test_decorator.py::TestDefaultFillingLogic::test_bind_validation_missing_required_args_has_no_accidental_call_hint -xvsWas generative AI tooling used to co-author this PR?
Generated-by: OpenAI Codex following the guidelines
Fixes #49875