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.
* Attachment "locale_404_bug.diff" added.
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>
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>
* Attachment "locale_404_bug_with_test.diff" added.
* 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>
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>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:5>
* needs_better_patch: 0 => 1
Comment:
I've left a comment on the PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:6>
* 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>
* 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>
* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:9>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27402#comment:10>
* 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>
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>