Opened 13 years ago
Closed 13 years ago
#19099 closed Bug (fixed)
Broken link email sent on redirect by i18n_patterns
| Reported by: | Aymeric Augustin | Owned by: | Aymeric Augustin |
|---|---|---|---|
| Component: | Core (Other) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
With the following settings:
MIDDLEWARE_CLASSES = {
# ...,
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
# ...,
}
SEND_BROKEN_LINKS_EMAIL = True
when a redirect to an i18n'd URL occurs, a broken link email is sent.
I'm attaching a failing test case.
This may be the expected behavior, but it's hard to diagnose. I started receiving broken link emails for '/', with various referrers and UAs. But going to that URL worked and didn't send an email, because there's no referrer when you go straight to the URL.
The solution might be documenting that CommonMiddleware must come before LocaleMiddleware. The commit logs say that they used to be in that order, but that we swapped them because APPEND_SLASH didn't work (I haven't re-verified this yet). And then I started receiving the broken link emails.
Attachments (1)
Change History (7)
by , 13 years ago
| Attachment: | 19099-failing-test-case.diff added |
|---|
comment:1 by , 13 years ago
| Owner: | changed from to |
|---|
comment:2 by , 13 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 13 years ago
comment:4 by , 13 years ago
| Component: | Internationalization → Core (Other) |
|---|---|
| Has patch: | set |
| Status: | new → assigned |
comment:6 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
After some more tests, here's what I've found.
Currently, the documentation says that
LocaleMiddlewareshould come beforeCommonMiddleware. It means that during response processing,CommonMiddleware.process_responseruns first, and it sends the broken link email beforeLocaleMiddleware.process_responsegets a chance to redirect to the expected URL. (That's very similar to #1859.)Putting
CommonMiddlewarebeforeLocaleMiddlewaresolves the problem with broken link emails, but creates other bugs; notably, missing trailing slashes aren't appended to URLs when the prefix is a non-default language.These results can be reproduced easily with:
i18n_patterns, such as the following:urlpatterns = i18n_patterns('views', url(r'^contact/$', 'contact'), )APPEND_SLASH = TrueLANGUAGE_CODE = 'en'LANGUAGES = (('en', _('English')), ('fr', _('French')))So, in the current state of things,
i18n_patternsandSEND_BROKEN_LINK_EMAILSare incompatible.The best solution I can think of is to move the broken link emails feature to its own middleware, say,
BrokenLinksMiddleware, that should come beforeLocaleMiddleware.Besides, 404 errors reporting by email sounds a bit archaic these days; does it really belong in
CommonMiddleware?It's a bit difficult to create a clean deprecation path for this change. I think
CommonMiddleware.process_responsecould raise warnings ifSEND_BROKEN_LINK_EMAILSisTruebutBrokenLinksMiddlewareisn't inMIDDLEWARE_CLASSES. In this case, during the deprecation period, it would callBrokenLinksMiddleware.process_response.