Opened 7 years ago

Closed 4 years ago

#14170 closed Bug (fixed)

Issue in get_language_from_request() if LANGUAGES setting is changed at runtime

Reported by: German M. Bravo Owned by: Bouke Haarsma
Component: Internationalization Version: 1.2
Severity: Normal Keywords:
Cc: German M. Bravo Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In get_language_from_request() in the translation module (trans_real.py), when you have multiple requests to it, and in requests you for some reason change the LANGUAGES setting... get_language_from_request() breaks the supported languages, because it assumes settings.LANGUAGES will never change, and it stores in _accepted the accepted .mo files (which's found they exist in the path), but in the next request, if the LANGUAGES changed, and the .mo file exists, it no longer checks for it to be supported in the new settings.LANGUAGES...

I know you shouldn't be changing settings such as LANGUAGES between requests, django doesn't even fully support it (thread safe, that's why I added the patch in ticket #12737)...but anyway, the thing is that if django is assumed not to ever change anything in the settings, many other things could probably be further optimized, but they're not, but it all generally works just fine (using the thread safe settings I mentioned), except for this time. I'm attaching a patch that would allow it to cache the _accepted found .mo files, but still check every time the _accepted language is really currently supported.

Attachments (1)

get_language_from_request.diff (728 bytes) - added by German M. Bravo 7 years ago.

Download all attachments as: .zip

Change History (10)

Changed 7 years ago by German M. Bravo

comment:1 Changed 7 years ago by Ramiro Morales

See #14628 re: Documenting which settings can be modified.

comment:2 Changed 7 years ago by Ramiro Morales

Summary: Issue in get_language_from_request() ?Issue in get_language_from_request() if LNGUAGES setting si changed at runtime
Triage Stage: UnreviewedSomeday/Maybe

comment:3 Changed 7 years ago by Ramiro Morales

Summary: Issue in get_language_from_request() if LNGUAGES setting si changed at runtimeIssue in get_language_from_request() if LANGUAGES setting is changed at runtime

comment:4 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:5 Changed 6 years ago by German M. Bravo

Cc: German M. Bravo added
Easy pickings: unset
UI/UX: unset

comment:6 Changed 5 years ago by Aymeric Augustin

Triage Stage: Someday/MaybeAccepted

The solution is to implement a setting_changed listener that resets the caches.

comment:7 Changed 4 years ago by Aymeric Augustin

Component: Core (Other)Internationalization

comment:8 Changed 4 years ago by Bouke Haarsma

Owner: changed from nobody to Bouke Haarsma
Status: newassigned

I've provided a fix for this issue in a PR: https://github.com/django/django/pull/1821

comment:9 Changed 4 years ago by Bouke Haarsma <bouke@…>

Resolution: fixed
Status: assignedclosed

In d0669843d0310a5c633548686ad8ce19404fc594:

Fixed #14170 -- Reset i18n cache when settings change

Note: See TracTickets for help on using tickets.
Back to Top