Locale set by a force_locale context manager leaks between multiple threads when force_locale is used in application context rather than request context. This can be fixed by using flask.globals._app_ctx_stack as recommended by Flask documentation on extension development. Unlike current_app, the object on top of the _app_ctx_stack object is different in every application context so any attributes set to it do not change the same attributes in a different application context. This pull request is similar to #144, but it adds a test for the bug that the change fixes and moves tests related to force_locale to a new test module.
Flask 2.2 deprecated _request_ctx_stack, and it will be removed in version 2.3, so I updated the last commit to use flask.g instead as recommended by the documentation.
Locale set by a
force_locale
context manager leaks between multiple threads whenforce_locale
is used in application context rather than request context. This can be fixed by usingflask.globals._app_ctx_stack
as recommended by Flask documentation on extension development. Unlikecurrent_app
, the object on top of the_app_ctx_stack
object is different in every application context so any attributes set to it do not change the same attributes in a different application context. This pull request is similar to #144, but it adds a test for the bug that the change fixes and moves tests related toforce_locale
to a new test module.