Opened 5 years ago

Closed 19 months ago

#14170 closed Bug (fixed)

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

Reported by: Kronuz Owned by: bouke
Component: Internationalization Version: 1.2
Severity: Normal Keywords:
Cc: Kronuz 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 Kronuz 5 years ago.

Download all attachments as: .zip

Change History (10)

Changed 5 years ago by Kronuz

comment:1 Changed 5 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 4 years ago by ramiro

  • Summary changed from Issue in get_language_from_request() ? to Issue in get_language_from_request() if LNGUAGES setting si changed at runtime
  • Triage Stage changed from Unreviewed to Someday/Maybe

comment:3 Changed 4 years ago by ramiro

  • Summary changed from Issue in get_language_from_request() if LNGUAGES setting si changed at runtime to Issue in get_language_from_request() if LANGUAGES setting is changed at runtime

comment:4 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:5 Changed 3 years ago by Kronuz

  • Cc Kronuz added
  • Easy pickings unset
  • UI/UX unset

comment:6 Changed 2 years ago by aaugustin

  • Triage Stage changed from Someday/Maybe to Accepted

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

comment:7 Changed 2 years ago by aaugustin

  • Component changed from Core (Other) to Internationalization

comment:8 Changed 19 months ago by bouke

  • Owner changed from nobody to bouke
  • Status changed from new to assigned

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

comment:9 Changed 19 months ago by Bouke Haarsma <bouke@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In d0669843d0310a5c633548686ad8ce19404fc594:

Fixed #14170 -- Reset i18n cache when settings change

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