Store forced locale per request #146
Closed
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_appproxy. This introduced the following bug:force_localeblock, which replacesbabel.locale_selector_funcwith lambda A. Originallocale_selector_funcis saved.force_localeblock, which replacesbabel.locale_selector_funcwith lambda B. Lambda A is saved.force_localeblock.babel.locale_selector_funcis replaced with the the originallocale_selector_func.force_localeblock.babel.locale_selector_funcis replaced by lambda A.Now
babel.locale_selector_funcis lambda A instead of the originallocale_selector_func.My solution to the problem:
Store forced
locale_selector_funcper request. Try to getlocale_selector_funcfirst from the request info and fall back to the one stored in the application object.