﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35170	LocaleMiddleware unexpectedly causes messages to be consumed under certain circumstances	Sylvain Fankhauser	nobody	"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."	Uncategorized	closed	Internationalization	dev	Normal	invalid			Unreviewed	0	0	0	0	0	0
