#35170: LocaleMiddleware unexpectedly causes messages to be consumed under
certain
circumstances
------------------------------------------------+------------------------
Reporter: Sylvain Fankhauser | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 5.0
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 |
------------------------------------------------+------------------------
Adding a message (with the messages contrib module) to the request and
then redirecting the user to an internationalized route without the
language prefix and a custom 404 template that consumes messages will
consume messages from the request, even though no 404 response is sent
back to the client.
I have set up a minimal reproduction project here:
https://github.com/sephii/django-localemiddleware-bug
To reproduce this problem, you’ll need:
1. An internationalized route (eg. `urlpatterns +=
i18n_patterns(path("foo/", views.foo))`)
2. A view that adds a message to the request (eg.
`messages.success(request, "Hello world")`) and then redirects to the
internationalized route without a language prefix
3. A 404.html template that consumes the request messages (eg. `{% for
message in messages %}{{ message }}{% endfor %}`)
Visiting the view defined in point 2 will result in a 302 to /foo/, which,
because of the 404.html template, will consume the message added by the
view in point 2 before redirecting to /en/foo/ (which won’t have any
message left to consume).
The bug is not in LocaleMiddleware per se, but is related to the way
LocaleMiddleware works: by catching any 404 and checking if it matches an
internationalized route, and if so redirecting to the correct route, but
at this point the 404 response has been rendered.
Ideally the only response Django should create is the redirect, and no 404
should be rendered.
--
Ticket URL: <https://code.djangoproject.com/ticket/35170>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018d7f1c7724-75ef5c8c-26c4-4474-9005-b8b3d194bc7a-000000%40eu-central-1.amazonses.com.