fix: Misleading load order of kwargs vs. args - #289
Conversation
This is a fix for issue laurentS#284 -- see that issue for more details.
Mukller
left a comment
There was a problem hiding this comment.
Thanks for fixing #284 — the two-step lookup correctly avoids the eager args[idx] evaluation that caused the IndexError, and it's applied consistently in both wrappers.
A few things before this can merge:
-
Please drop the
pyproject.tomlversion bump — releases are cut by the maintainer, and carrying0.1.10 -> 0.1.11in a bugfix PR will conflict with other pending changes. -
Prefer an explicit
Nonecheck over truthiness:if not request:falls back toargs[idx]whenever the kwarg value is falsy, which subtly changes semantics for an explicitly-passedrequest=None.if request is None:keeps the original contract and states the intent. -
The PR ships without a regression test. This exact crash class is why the issue exists; something like decorating a handler where
requestarrives as a keyword argument while positionalargsare shorter thanidx, then asserting the endpoint responds instead of raisingIndexError, would lock the fix in. The existing FastAPI extension tests intests/test_fastapi_extension.pylook like a good home for it.
|
Hey @Mukller , Thanks for the helpful PR comments -- all good points.
Let me know what you think :)
|
Summary
Fix for issue #284 .
User raised an issue that
argswere indexed too soon - beforekwargswere searched.This was due to trying to make this operation a 1-liner, and resulted in Python attempting to parse
argsbefore checkingkwargs.User supplied this proposed fix, which looks good and appears to cause no other issues.
Checks done