Opened 14 years ago

Closed 11 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 14 years ago.

Download all attachments as: .zip

Change History (10)

by German M. Bravo, 14 years ago

comment:1 by Ramiro Morales, 14 years ago

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

comment:2 by Ramiro Morales, 14 years ago

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 by Ramiro Morales, 14 years ago

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 by Julien Phalip, 14 years ago

Severity: Normal
Type: Bug

comment:5 by German M. Bravo, 13 years ago

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

comment:6 by Aymeric Augustin, 12 years ago

Triage Stage: Someday/MaybeAccepted

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

comment:7 by Aymeric Augustin, 12 years ago

Component: Core (Other)Internationalization

comment:8 by Bouke Haarsma, 11 years ago

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 by Bouke Haarsma <bouke@…>, 11 years ago

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