Opened 11 years ago
Closed 11 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)
Changed 11 years ago by
Attachment: | 19099-failing-test-case.diff added |
---|
comment:1 Changed 11 years ago by
Owner: | changed from nobody to Aymeric Augustin |
---|
comment:2 Changed 11 years ago by
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 Changed 11 years ago by
comment:4 Changed 11 years ago by
Component: | Internationalization → Core (Other) |
---|---|
Has patch: | set |
Status: | new → assigned |
comment:6 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
After some more tests, here's what I've found.
Currently, the documentation says that
LocaleMiddleware
should come beforeCommonMiddleware
. It means that during response processing,CommonMiddleware.process_response
runs first, and it sends the broken link email beforeLocaleMiddleware.process_response
gets a chance to redirect to the expected URL. (That's very similar to #1859.)Putting
CommonMiddleware
beforeLocaleMiddleware
solves 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:APPEND_SLASH = True
LANGUAGE_CODE = 'en'
LANGUAGES = (('en', _('English')), ('fr', _('French')))
So, in the current state of things,
i18n_patterns
andSEND_BROKEN_LINK_EMAILS
are 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_response
could raise warnings ifSEND_BROKEN_LINK_EMAILS
isTrue
butBrokenLinksMiddleware
isn't inMIDDLEWARE_CLASSES
. In this case, during the deprecation period, it would callBrokenLinksMiddleware.process_response
.