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.
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
callsteardown_request
on exit, resulting onreal_request
being pop fromdebug_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.