Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store forced locale per request #146

Closed
wants to merge 1 commit into from
Closed

Store forced locale per request #146

wants to merge 1 commit into from

Conversation

tvuotila
Copy link

@tvuotila tvuotila commented Oct 25, 2018

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
Copy link

quantus commented Nov 1, 2018

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

@tvuotila
Copy link
Author

tvuotila commented Nov 2, 2018

@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
Copy link
Author

tvuotila commented Aug 23, 2019

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