Skip to content

Store forced locale per request#146

Closed
tvuotila wants to merge 1 commit into
python-babel:masterfrom
tvuotila:feature/store-forced-locale-per-request
Closed

Store forced locale per request#146
tvuotila wants to merge 1 commit into
python-babel:masterfrom
tvuotila:feature/store-forced-locale-per-request

Conversation

@tvuotila

@tvuotila tvuotila commented Oct 25, 2018

Copy link
Copy Markdown

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:

  1. Request A enters force_locale block, which replaces babel.locale_selector_func with lambda A. Original locale_selector_func is saved.
  2. Request A does some i/o work.
  3. Request B is started. Request B enters force_locale block, which replaces babel.locale_selector_func with lambda B. Lambda A is saved.
  4. Request B does some i/o work.
  5. Request A finishes the i/o work and exits force_locale block. babel.locale_selector_func is replaced with the the original locale_selector_func.
  6. Request B finishes the i/o work and exits force_locale block. babel.locale_selector_func is replaced by lambda A.

Now babel.locale_selector_func is lambda A instead of the original locale_selector_func.

My solution to the problem:
Store forced locale_selector_func per request. Try to get locale_selector_func first from the request info and fall back to the one stored in the application object.

Allow multiple request to share the same application.
@quantus

quantus commented Nov 1, 2018

Copy link
Copy Markdown

@tvuotila: Isn't this the same as #125? Can you check if these changes are identical, or if there are any differences?

@tvuotila

tvuotila commented Nov 2, 2018

Copy link
Copy Markdown
Author

@tvuotila: Isn't this the same as #125? Can you check if these changes are identical, or if there are any differences?

They solve the same problem, but I notice an issue there.

@tvuotila

tvuotila commented Aug 23, 2019

Copy link
Copy Markdown
Author

I close this because #125 is better

@tvuotila tvuotila closed this Aug 23, 2019
@tvuotila tvuotila deleted the feature/store-forced-locale-per-request branch February 4, 2022 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants