{"action":"created","issue":{"url":"https://api.github.com/repos/python-babel/flask-babel/issues/146","repository_url":"https://api.github.com/repos/python-babel/flask-babel","labels_url":"https://api.github.com/repos/python-babel/flask-babel/issues/146/labels{/name}","comments_url":"https://api.github.com/repos/python-babel/flask-babel/issues/146/comments","events_url":"https://api.github.com/repos/python-babel/flask-babel/issues/146/events","html_url":"https://github.com/python-babel/flask-babel/pull/146","id":374082289,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI1ODY1MzAz","number":146,"title":"Store forced locale per request","user":{"login":"tvuotila","id":3326999,"node_id":"MDQ6VXNlcjMzMjY5OTk=","avatar_url":"https://avatars2.githubusercontent.com/u/3326999?v=4","gravatar_id":"","url":"https://api.github.com/users/tvuotila","html_url":"https://github.com/tvuotila","followers_url":"https://api.github.com/users/tvuotila/followers","following_url":"https://api.github.com/users/tvuotila/following{/other_user}","gists_url":"https://api.github.com/users/tvuotila/gists{/gist_id}","starred_url":"https://api.github.com/users/tvuotila/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tvuotila/subscriptions","organizations_url":"https://api.github.com/users/tvuotila/orgs","repos_url":"https://api.github.com/users/tvuotila/repos","events_url":"https://api.github.com/users/tvuotila/events{/privacy}","received_events_url":"https://api.github.com/users/tvuotila/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-10-25T18:49:22Z","updated_at":"2018-11-02T08:04:27Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/python-babel/flask-babel/pulls/146","html_url":"https://github.com/python-babel/flask-babel/pull/146","diff_url":"https://github.com/python-babel/flask-babel/pull/146.diff","patch_url":"https://github.com/python-babel/flask-babel/pull/146.patch"},"body":"Allow multiple request to share the same application.\r\n\r\nProblem:\r\nWe 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.\r\n\r\nIn my tests, I managed to have two requests use the same application object through `current_app` proxy. This introduced the following bug:\r\n\r\n1. Request A enters `force_locale` block, which replaces `babel.locale_selector_func` with lambda A. Original `locale_selector_func` is saved.\r\n2. Request A does some i/o work.\r\n3. Request B is started. Request B enters `force_locale` block, which replaces `babel.locale_selector_func` with lambda B. Lambda A is saved.\r\n4. Request B does some i/o work.\r\n5. 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`.\r\n6. Request B finishes the i/o work and exits `force_locale` block. `babel.locale_selector_func` is replaced by lambda A.\r\n\r\nNow `babel.locale_selector_func` is lambda A instead of the original `locale_selector_func`.\r\n\r\nMy solution to the problem:\r\nStore 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."},"comment":{"url":"https://api.github.com/repos/python-babel/flask-babel/issues/comments/435301115","html_url":"https://github.com/python-babel/flask-babel/pull/146#issuecomment-435301115","issue_url":"https://api.github.com/repos/python-babel/flask-babel/issues/146","id":435301115,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNTMwMTExNQ==","user":{"login":"tvuotila","id":3326999,"node_id":"MDQ6VXNlcjMzMjY5OTk=","avatar_url":"https://avatars2.githubusercontent.com/u/3326999?v=4","gravatar_id":"","url":"https://api.github.com/users/tvuotila","html_url":"https://github.com/tvuotila","followers_url":"https://api.github.com/users/tvuotila/followers","following_url":"https://api.github.com/users/tvuotila/following{/other_user}","gists_url":"https://api.github.com/users/tvuotila/gists{/gist_id}","starred_url":"https://api.github.com/users/tvuotila/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tvuotila/subscriptions","organizations_url":"https://api.github.com/users/tvuotila/orgs","repos_url":"https://api.github.com/users/tvuotila/repos","events_url":"https://api.github.com/users/tvuotila/events{/privacy}","received_events_url":"https://api.github.com/users/tvuotila/received_events","type":"User","site_admin":false},"created_at":"2018-11-02T08:04:27Z","updated_at":"2018-11-02T08:04:27Z","author_association":"NONE","body":"> @tvuotila: Isn't this the same as #125? Can you check if these changes are identical, or if there are any differences?\r\n\r\nThey solve the same problem, but I notice an issue there."}}
{"actor":{"display_login":"tvuotila"}}