Opened 6 years ago

Closed 6 years ago

#29842 closed Uncategorized (worksforme)

For some reason self.client.get("/") return a Resolve404 error even with the LocaleMiddleware

Reported by: Rémy Hubscher Owned by: nobody
Component: Uncategorized Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This tests fails:

class LocaleMiddlewareTest(TestCase):

    def test_locale_middleware_redirects_to_localized_url(self):
        resp = self.client.get("/")
        self.assertRedirects(resp, "/fr/")

While this one uses the LocaleMiddleware:

class LocaleMiddlewareTest(TestCase):

    def test_locale_middleware_redirects_to_localized_url(self):
        resp = self.client.get("/home")
        self.assertRedirects(resp, "/fr/home")

Change History (3)

comment:1 by Tim Graham, 6 years ago

Resolution: invalid
Status: newclosed

You haven't given any details about how we can reproduce the issue. Please use TicketClosingReasons/UseSupportChannels until you confirm a bug in Django.

comment:2 by Rémy Hubscher, 6 years ago

Resolution: invalid
Status: closednew

You are too quick for me, I didn't had time to elaborate.

Initially I thought this was a bug with the Django Test Client so I landed the code but it also happened in real life.

I was planning to create a pull-request with a failing test but you closed the issue too quickly and since a pull-request need to be linked to an issue I created the issue first.

The minimum setup to reproduce is to use the LocaleMiddleware with the following urls.py file.

urlpatterns = [
     path("chefclub-admin/", admin.site.urls),
    path(
        "chefclub-admin", RedirectView.as_view(url="chefclub-admin/", query_string=True)
    ),
]

urlpatterns += i18n_patterns(
    path("", views.index, name="index"),
)
Version 0, edited 6 years ago by Rémy Hubscher (next)

comment:3 by Rémy Hubscher, 6 years ago

Resolution: worksforme
Status: newclosed

Ok I build an app from scratch with Django master and I tried to reproduce without success so far.

from django.conf.urls import url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.http import HttpResponse, Http404
from django.urls import path


def index(request):
    return HttpResponse("ok")


def handle_url(request, wordpress_url):
    raise Http404("No mapping found for {}".format(wordpress_url))


urlpatterns = [
    url(r'^admin/', admin.site.urls),
]

urlpatterns += i18n_patterns(
    path("", index, name="index"),
)

urlpatterns += [path("<path:wordpress_url>", handle_url)]

Note: See TracTickets for help on using tickets.
Back to Top