Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Allow multiple request to share the same application.
Problem:
We are running Flask with Gunicorn with gevent worker type. This means, that when a request processing is waiting for an i/o, another request processing can start.
In my tests, I managed to have two requests use the same application object through
current_app
proxy. This introduced the following bug:force_locale
block, which replacesbabel.locale_selector_func
with lambda A. Originallocale_selector_func
is saved.force_locale
block, which replacesbabel.locale_selector_func
with lambda B. Lambda A is saved.force_locale
block.babel.locale_selector_func
is replaced with the the originallocale_selector_func
.force_locale
block.babel.locale_selector_func
is replaced by lambda A.Now
babel.locale_selector_func
is lambda A instead of the originallocale_selector_func
.My solution to the problem:
Store forced
locale_selector_func
per request. Try to getlocale_selector_func
first from the request info and fall back to the one stored in the application object.