#35170: LocaleMiddleware unexpectedly causes messages to be consumed under certain circumstances -------------------------------------+------------------------------------- Reporter: Sylvain Fankhauser | Owner: nobody Type: Uncategorized | Status: closed Component: | Version: dev Internationalization | Severity: Normal | Resolution: invalid Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by Natalia Bidart):
* status: new => closed * type: Bug => Uncategorized * version: 5.0 => dev * resolution: => invalid Comment: Hello Sylvain Fankhauser! Thank you for your interest in making Django better. I took a close look at this report, I cloned the reproducer repo and followed your steps. I do see what you are describing here, but I also noted a few cases that raise concerns: * In my experience, 404 templates should ideally be as static as possible. Consuming/showing the messages from the request feels like a code smell. * Redirecting to a hard-coded URL is an anti-pattern; ideally, the code would use proper calls to `reverse`. * The URL `/foobar/` is clearly a 404, so manually redirecting to this URL is another unexpected aspect of the code. If hard-coding is essential, why not redirecting to `/<lang>/foobar/`? I made this slight change to the given code: {{{#!diff diff --git a/testdjango/urls.py b/testdjango/urls.py index c89638c..088a45d 100644 --- a/testdjango/urls.py +++ b/testdjango/urls.py @@ -17,12 +17,12 @@ from django.conf.urls.i18n import i18n_patterns from django.contrib import messages from django.http import HttpResponse from django.shortcuts import redirect -from django.urls import path +from django.urls import path, reverse def home(request): messages.error(request, "Hello world") - return redirect("/foobar/") + return redirect(reverse("foobar")) def foobar(request): @@ -35,5 +35,5 @@ urlpatterns = [ ] urlpatterns += i18n_patterns( - path("foobar/", foobar), + path("foobar/", foobar, name="foobar"), ) }}} and messages are not consumed any longer, because there is no 404 being raised anywhere in the call chain. Honestly I don't see where Django is at fault here, the way the i18n URLs are resolved involves raising a `Resolver404` exception which triggers the creation of a `HttpResponseNotFound` instance (which needs the template rendered to be created). I'll closing as `invalid` but if you have more information or if you disagree with the resolution, please reach out to the [https://forum.djangoproject.com/c/users/6 Django forum]. -- Ticket URL: <https://code.djangoproject.com/ticket/35170#comment:1> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018d9e1b9108-3c2dc02e-5ba9-4dae-b2fe-6bf466bbdb03-000000%40eu-central-1.amazonses.com.