Skip to content

TypeError when instantiating Starlette middleware with positional arguments #3246

Description

@phooijenga

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.7.1

Steps to Reproduce

I have a FastAPI app with some middleware, one of which I want to pass a positional argument, like this:

app = FastAPI(
    middleware=[
        Middleware(RequestLoggerMiddleware, "app.request"),
    ],
)

This works fine when Sentry is not enabled, but causes a TypeError when it is. The problem does not occur when I use a keyword argument instead.

Expected Result

I expect the app to work the same way with and without Sentry enabled.

Actual Result

File "/app/app.py", line 103, in <module>
  middleware=[Middleware(RequestLoggerMiddleware, "app.request")],
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: patch_middlewares.<locals>._sentry_middleware_init() takes 2 positional arguments but 3 were given

Metadata

Metadata

Assignees

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions