Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix middleware being patched multiple times when using FastAPI #1841

Merged
merged 8 commits into from Jan 19, 2023

Conversation

JohnnyDeuss
Copy link
Contributor

@JohnnyDeuss JohnnyDeuss commented Jan 16, 2023

When the StarletteIntegration is used in a FastAPI app, as instructed in the docs, the AuthenticationMiddleware and ExceptionMiddleware get patched every time add_middleware or add_exception_handler is called, since these methods call build_middleware_stack, where patched Middleware instances are repatched without checking if they were already patched.

If these functions are called enough times, Python registers this as infinite recursion (as we've discovered).

The changes look broad, but amount to the addition of two if not_yet_patched checks and indentation.

@antonpirker
Copy link
Member

Hey @JohnnyDeuss
Can you fix the "Lint Sources" issues shown above?
You probably just need to reformat the code locally by calling black tests sentry_sdk in the root directory.

@antonpirker antonpirker merged commit 0714d9f into getsentry:master Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants