#27402 closed Bug (fixed)
When using i18n_patterns and prefix_default_language=False, 404 page redirects incorrectly
Reported by: | Hovi | Owned by: | nobody |
---|---|---|---|
Component: | Internationalization | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Attachments (2)
Change History (14)
by , 8 years ago
Attachment: | locale_404_bug.diff added |
---|
comment:1 by , 8 years ago
comment:2 by , 8 years ago
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.
by , 8 years ago
Attachment: | locale_404_bug_with_test.diff added |
---|
comment:3 by , 8 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
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.
comment:4 by , 8 years ago
Yeah, new merged tests actually broke it by coincidentally using similar url pattern.
comment:5 by , 8 years ago
Patch needs improvement: | unset |
---|
comment:7 by , 8 years ago
Patch needs improvement: | unset |
---|
I've submitted pull request https://github.com/django/django/pull/7483 with a improved version of the patch.
comment:8 by , 8 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
The PR looks good to me. Thanks !
comment:9 by , 8 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
comment:10 by , 8 years ago
Patch needs improvement: | unset |
---|
Can you add a test? (Just to be sure, #27063 doesn't solve the issue?)