Skip to content

Keep positional-only arguments in the task argument check - #10870

Open
arieleven wants to merge 2 commits into
celery:mainfrom
arieleven:fix/head-from-fun-positional-only
Open

arieleven wants to merge 2 commits into
celery:mainfrom
arieleven:fix/head-from-fun-positional-only

Conversation

@arieleven

Copy link
Copy Markdown

Note: Before submitting this pull request, please review our contributing
guidelines
.

Description

apply_async() checks the arguments of a call against the task signature with a function generated by head_from_fun(). The generated function is written from the full argspec, which lists positional-only parameters together with the regular ones, so the / marker is lost and the check no longer matches the task:

@app.task
def scale(value, /, **options): ...

scale.delay(1, value=2)
# TypeError: scale() got multiple values for argument 'value'
# (the call is valid: scale(1, value=2) works)

@app.task
def add(x, /, y): ...

add.delay(x=1, y=2)
# accepted and sent; fails later in the worker

_argsfromspec() now takes the number of positional-only parameters (read from the code object of the same callable) and writes the / in the generated header. Callables without a code object are unchanged.

Tests: five cases in test_head_from_fun (plain, name reused as a keyword, all parameters positional-only, combined with keyword-only, bound) and test_typing__positional_only in test_tasks.py. All six fail on main. Checked on Python 3.12 and 3.14.

head_from_fun() builds the function that apply_async() calls to check
the arguments of a task. It was generated from the full argspec, which
lists positional-only arguments together with the regular ones, so the
"/" marker was lost.

A task defined as f(x, /, **kwargs) could not be called with a keyword
named x ("got multiple values for argument"), and a call that passed a
positional-only argument by keyword was accepted and only failed in the
worker.

@MehrazRumman MehrazRumman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked at 1e6ff97.

  • The bug is real, and the fix is in the right place. getfullargspec doesn't mark positional-only parameters, so the generated header lost the /. Reading co_posonlyargcount from the same callable and inserting / after that many positional entries gives the right header. It also works with defaults, *args, keyword-only parameters and **kwargs. For example, def f(a, b=1, /, c=2, *rest, d, **kw) now generates def f(a, b=0, /, c=1, *rest, d, **kw).
  • t/unit/utils/test_functional.py and t/unit/tasks/test_tasks.py pass (219 passed, 1 xfailed). All five new head_from_fun cases and test_typing__positional_only fail against main.
  • Callables without a __code__ fall back to 0 and are unchanged. For class-based callables, fun.__call__ is a bound method whose __code__ count includes self, the same as the argspec, so the two stay consistent.

The CI workflows for this commit are still waiting for maintainer approval. Looks good to me.

@auvipy
auvipy self-requested a review October 17, 2026 10:57
@auvipy auvipy added this to the 5.7.x milestone Oct 17, 2026
@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.55%. Comparing base (2fa4aa2) to head (98f1aea).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10870      +/-   ##
==========================================
- Coverage   90.56%   90.55%   -0.01%     
==========================================
  Files         153      153              
  Lines       21367    21370       +3     
  Branches     2608     2609       +1     
==========================================
+ Hits        19350    19352       +2     
  Misses       1704     1704              
- Partials      313      314       +1     
Flag Coverage Δ
unittests 90.53% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants