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

Support applications using flask.copy_current_request_context #231

Merged
merged 2 commits into from Jan 17, 2024

Conversation

glic3rinu
Copy link

@glic3rinu glic3rinu commented Jan 9, 2024

Toolbar doesn't currently work if an application calls flask.copy_current_request_context at any point during request handling.

Note that this decorator is typically used when an application uses threads that need access to request context.

flask.copy_current_request_context calls teardown_request on exit, resulting on real_request being pop from debug_toolbars dict ahead of time, and not being present when debug toolbar processes the response. Ultimately resulting on the toolbar not being displayed.

This PR solves this problem by allocation debug_toolbars dict inside a contextvar, so threads/coroutines will leave toolbar state from the main/parent request alone.

Copy link
Contributor

@macnewbold macnewbold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this, and for the well-written explanation of how and why this is important.

@macnewbold macnewbold merged commit 9b63ad1 into pallets-eco:master Jan 17, 2024
10 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants