Skip to content

Code executes prematurely because of request #284

Description

@game-hipe

Describe the bug
When receiving a Request via kwargs, an IndexError occurs because it executes the code args[idx] if args else None before kwargs.get, under the following conditions:

To Reproduce
Image

Expected behavior
It should first execute

kwargs.get("request")

and then

args[idx] if args else None

Screenshots
Image

Your app (please complete the following information):

  • My app is fastapi==0.138.1
    -pPython3.14.6
  • slowapi version is latest == 0.1.10

Additional context
The fix is simple: just rewrite line 726 in the file as
Image

In code:

#request = kwargs.get("request", args[idx] if args else None) OLD
                        
request = kwargs.get("request")
if not request:
    request = args[idx] if args else None # NEW

Also for the synchronous version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions