[Django] #32768: An incorrect language is sometimes displayed - redirects adding a language code to a path can be inappropriate cached by HTTP caches

0 views
Skip to first unread message

Django

unread,
May 19, 2021, 7:08:31 AM5/19/21
to django-...@googlegroups.com
#32768: An incorrect language is sometimes displayed - redirects adding a language
code to a path can be inappropriate cached by HTTP caches
------------------------------------------------+------------------------
Reporter: ahaywardtvuk | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
We have a multi-lingual site using LocaleMiddleware. With a CDN and
caching reverse proxy in use, the following sequence of events can happen:

* Fetch https://example.com/some-page/ with Accept-Language header 'de-
DE,de;q=0.9'. A redirect to https://example.com/de/some-page/ is returned.
* Fetch it again with Accept-Language header 'fr-FR,fr;q=0.9'. The cached
redirect is returned by HTTP caches and the German page is displayed
instead of the French one.

LocaleMiddleware is issuing a redirect based on the detected language from
the Accept-Language header or from the cookie chosen by
settings.LANGUAGE_COOKIE_NAME but is not telling caches that it has used
these headers.

Adding a Vary header fixes this.

--
Ticket URL: <https://code.djangoproject.com/ticket/32768>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 19, 2021, 7:24:29 AM5/19/21
to django-...@googlegroups.com
#32768: An incorrect language is sometimes displayed - redirects adding a language
code to a path can be inappropriate cached by HTTP caches
-------------------------------------+-------------------------------------
Reporter: Alex Hayward | Owner: nobody
Type: Bug | Status: new
Component: | Version: 3.1
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alex Hayward):

* has_patch: 0 => 1


Comment:

I've created a pull request, https://github.com/django/django/pull/14416

--
Ticket URL: <https://code.djangoproject.com/ticket/32768#comment:1>

Django

unread,
May 20, 2021, 2:45:47 AM5/20/21
to django-...@googlegroups.com
#32768: An incorrect language is sometimes displayed - redirects adding a language
code to a path can be inappropriate cached by HTTP caches
--------------------------------------+------------------------------------
Reporter: Alex Hayward | Owner: nobody

Type: Bug | Status: new
Component: Internationalization | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Carlton Gibson):

* stage: Unreviewed => Accepted


Comment:

OK, I think this looks right. Let's take it for review to get other eyes
on it. Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/32768#comment:2>

Django

unread,
Sep 1, 2021, 6:49:59 AM9/1/21
to django-...@googlegroups.com
#32768: An incorrect language is sometimes displayed - redirects adding a language
code to a path can be inappropriate cached by HTTP caches
-------------------------------------+-------------------------------------
Reporter: Alex Hayward | Owner: nobody
Type: Bug | Status: new
Component: | Version: 3.1
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32768#comment:3>

Django

unread,
Sep 1, 2021, 8:02:51 AM9/1/21
to django-...@googlegroups.com
#32768: An incorrect language is sometimes displayed - redirects adding a language
code to a path can be inappropriate cached by HTTP caches
-------------------------------------+-------------------------------------
Reporter: Alex Hayward | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 3.1
Internationalization |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"eeed488a3439c5c5c3f0b5991ee400851057e127" eeed488a]:
{{{
#!CommitTicketReference repository=""
revision="eeed488a3439c5c5c3f0b5991ee400851057e127"
Fixed #32768 -- Added Vary header when redirecting to prefixed i18n
pattern.

get_language_from_request() uses Accept-Language and/or Cookie to
determine the
correct redirect. Upstream caches need the matching Vary header to cache
the
result.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32768#comment:4>

Reply all
Reply to author
Forward
0 new messages