Skip to content

fix: align positional argument parsing with parameter positions - #667

Merged
s3rius merged 2 commits into
taskiq-python:masterfrom
juanmicl:fix/worker-arg-parse-alignment
Aug 31, 2026
Merged

fix: align positional argument parsing with parameter positions#667
s3rius merged 2 commits into
taskiq-python:masterfrom
juanmicl:fix/worker-arg-parse-alignment

Conversation

@juanmicl

Copy link
Copy Markdown
Contributor

Closes: #666

parse_params mapped positional arguments to annotations using a counter
that only advanced for annotated parameters, so any unannotated
positional parameter shifted every following argument onto the wrong
annotation (values silently coerced by the wrong type, annotated
parameters never validated).

This PR decouples the positional slot index from annotation presence:

  • every POSITIONAL_ONLY / POSITIONAL_OR_KEYWORD parameter advances
    the slot index, annotated or not;
  • parsing only happens when the parameter actually has an annotation;
  • *args annotations now coerce all remaining positional arguments
    (previously only the first element was coerced);
  • keyword-only parameters go straight to the kwargs branch.

Behavior for fully-annotated signatures is unchanged, all existing
test_params_parser.py cases pass as-is.

Validation: full suite passes (pytest -q, 313 tests), black, ruff
and mypy clean (mypy reports the same 2 pre-existing errors in
taskiq/serializers/ as on master).

@s3rius

s3rius commented Aug 30, 2026

Copy link
Copy Markdown
Member

Okay, that seems like it might some the problem. But would you mind adding some tests to validate the fix?

@juanmicl

Copy link
Copy Markdown
Contributor Author

Added 9 tests to tests/receiver/test_params_parser.py covering the cases from the issue:

  • unannotated parameters are left untouched (request_id keeps its string value)
  • annotated parameters after an unannotated one are parsed in their own position (int and datetime)
  • the Can't parse argument N warning now points at the right index
  • *args coercion applies to all elements, not just the first
  • keyword-only params and positional params passed as kwargs

Six of them fail on master and pass with the fix. Full suite passes locally (322 tests), ruff/black/mypy clean.

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.63%. Comparing base (9fa2a1c) to head (e7770d2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #667      +/-   ##
==========================================
+ Coverage   82.55%   82.63%   +0.08%     
==========================================
  Files          69       69              
  Lines        2717     2730      +13     
==========================================
+ Hits         2243     2256      +13     
  Misses        474      474              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@s3rius
s3rius merged commit c4b8666 into taskiq-python:master Aug 31, 2026
35 checks passed
@s3rius

s3rius commented Aug 31, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution. Will appear in the next release.

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.

Worker misparses positional arguments when a preceding parameter lacks a type annotation

2 participants