[Django] #27402: When using i18n_patterns and prefix_default_language=False, 404 page redirects incorrectly

29 views
Skip to first unread message

Django

unread,
Oct 28, 2016, 6:10:03 PM10/28/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
------------------------------------------------+------------------------
Reporter: Hovi | Owner: nobody
Type: Uncategorized | Status: new
Component: Internationalization | Version: 1.10
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 |
------------------------------------------------+------------------------
Hello,

I just migrated to 1.10.2 using new cool localization with
prefix_default_language=False, replacing solid-i18n-urls:
https://github.com/st4lk/django-solid-i18n-urls
Only smaller issue is, that whenever I go to 404 page, I get redirected to
/en/THE_OLD_URL/ (en is default language in my case).

My guess is bug in LocaleMiddleware, language_path variable is being
constructed always using language code even in cases when there shouldn't
be (default language).
I attached simple fix, that seems to work it out for me.

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

Django

unread,
Oct 28, 2016, 6:10:19 PM10/28/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
-------------------------------------+-------------------------------------

Reporter: Hovi | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 1.10
Internationalization |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hovi):

* Attachment "locale_404_bug.diff" added.

Django

unread,
Oct 28, 2016, 9:35:20 PM10/28/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
-------------------------------------+-------------------------------------

Reporter: Hovi | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 1.10
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Can you add a test? (Just to be sure, #27063 doesn't solve the issue?)

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

Django

unread,
Oct 29, 2016, 6:24:07 AM10/29/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
-------------------------------------+-------------------------------------

Reporter: Hovi | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 1.10
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Hovi):

It's definitely not same thing as #27063. I took a deeper look and it is a
little more complicated.
When I just added test, it was passing anyway and it turned out problem is
little more specific to my case (it is still bug though).
I have something like this in my url as last record without i18npatterns:

r'^(?P<group1>.+)/(?P<group2>.+)/$

So what exactly happens here:
1, language_path is constructed as /en/non-existent-page instead of /non-
existent-page
2, language_path passes is_valid_path(language_path,... because that url
matches my regex.
3, that leads to redirect

Code after that constructs url for redirect (variable language_url) also
doesn't take into account possibility default language without prefix, so
that part may also need reviewing but I am not even sure if that can ever
happen.

Attaching simple test.

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

Django

unread,
Oct 29, 2016, 6:24:48 AM10/29/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
-------------------------------------+-------------------------------------

Reporter: Hovi | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 1.10
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hovi):

* Attachment "locale_404_bug_with_test.diff" added.

Django

unread,
Nov 1, 2016, 4:41:55 PM11/1/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
--------------------------------------+------------------------------------
Reporter: Hovi | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

I haven't looked into the details, but the new test isn't passing. Please
send a pull request if you're able to improve the patch.

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

Django

unread,
Nov 1, 2016, 5:24:21 PM11/1/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
--------------------------------------+------------------------------------
Reporter: Hovi | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Hovi):

Yeah, new merged tests actually broke it by coincidentally using similar
url pattern.

[https://github.com/django/django/pull/7461]

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

Django

unread,
Nov 1, 2016, 6:17:10 PM11/1/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
--------------------------------------+------------------------------------
Reporter: Hovi | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 1.10

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 Tim Graham):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:5>

Django

unread,
Nov 4, 2016, 1:07:18 AM11/4/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
--------------------------------------+------------------------------------
Reporter: Hovi | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by François Freitag):

* needs_better_patch: 0 => 1


Comment:

I've left a comment on the PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:6>

Django

unread,
Nov 5, 2016, 8:54:26 AM11/5/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
--------------------------------------+------------------------------------
Reporter: Hovi | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 1.10

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 Krzysztof Urbaniak):

* needs_better_patch: 1 => 0


Comment:

I've submitted pull request https://github.com/django/django/pull/7483
with a improved version of the patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:7>

Django

unread,
Nov 11, 2016, 10:54:40 AM11/11/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
-------------------------------------+-------------------------------------
Reporter: Hovi | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.10
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 François Freitag):

* stage: Accepted => Ready for checkin


Comment:

The [https://github.com/django/django/pull/7483 PR] looks good to me.
Thanks !

--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:8>

Django

unread,
Nov 28, 2016, 2:01:58 PM11/28/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
--------------------------------------+------------------------------------
Reporter: Hovi | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:9>

Django

unread,
Nov 29, 2016, 1:47:34 AM11/29/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
--------------------------------------+------------------------------------
Reporter: Hovi | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 1.10

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 François Freitag):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:10>

Django

unread,
Nov 29, 2016, 1:42:35 PM11/29/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
--------------------------------------+------------------------------------
Reporter: Hovi | Owner: nobody
Type: Bug | Status: closed
Component: Internationalization | Version: 1.10
Severity: Normal | Resolution: fixed
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 Tim Graham <timograham@…>):

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


Comment:

In [changeset:"b8a815e9dfea89034ede7ff786551f89af84a31b" b8a815e9]:
{{{
#!CommitTicketReference repository=""
revision="b8a815e9dfea89034ede7ff786551f89af84a31b"
Fixed #27402 -- Fixed incorrect LocaleMiddleware redirects with
prefix_default_language=False.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:11>

Django

unread,
Nov 29, 2016, 1:54:38 PM11/29/16
to django-...@googlegroups.com
#27402: When using i18n_patterns and prefix_default_language=False, 404 page
redirects incorrectly
--------------------------------------+------------------------------------
Reporter: Hovi | Owner: nobody
Type: Bug | Status: closed
Component: Internationalization | Version: 1.10

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"81b5971b1ce044448466791b3c6f795b66c666d7" 81b5971b]:
{{{
#!CommitTicketReference repository=""
revision="81b5971b1ce044448466791b3c6f795b66c666d7"
[1.10.x] Fixed #27402 -- Fixed incorrect LocaleMiddleware redirects with
prefix_default_language=False.

Backport of b8a815e9dfea89034ede7ff786551f89af84a31b from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:12>

Reply all
Reply to author
Forward
0 new messages