#34377 closed Bug (fixed)

AdminSite.catch_all_view() drops query string in redirects

Reported by: Dominique Bischof Owned by: Dominique Bischof
Component: contrib.admin Version: 4.1
Severity: Normal Keywords:
Cc: Carlton Gibson 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

#31747 introduced AdminSite.catch_all_view(). However, in the process it broke the ability to redirect with settings.APPEND_SLASH = True when there are query strings.

Provided URL: http://127.0.0.1:8000/admin/auth/foo?id=123
Expected redirect: http://127.0.0.1:8000/admin/auth/foo/?id=123
Actual redirect: http://127.0.0.1:8000/admin/auth/foo/

This seems to be because the redirect in question does not include the query strings (such as via request.META['QUERY_STRING']):
return HttpResponsePermanentRedirect("%s/" % request.path)
https://github.com/django/django/blob/c57ff9ba5e251cd4c2761105a6046662c08f951e/django/contrib/admin/sites.py#L456

Change History (6)

comment:1 by Mariusz Felisiak, 21 months ago

Cc: Carlton Gibson Jon Dufresne added
Easy pickings: unset
Triage Stage: UnreviewedAccepted

Thanks for the report! Using get_full_path() should fix the issue:

  • django/contrib/admin/sites.py

    diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
    index 61be31d890..96c54e44ad 100644
    a b class AdminSite:  
    453453                pass
    454454            else:
    455455                if getattr(match.func, "should_append_slash", True):
    456                     return HttpResponsePermanentRedirect("%s/" % request.path)
     456                    return HttpResponsePermanentRedirect(request.get_full_path(force_append_slash=True))
    457457        raise Http404
    458458
    459459    def _build_app_dict(self, request, label=None):

Would you like to prepare PR via GitHub? (a regression test is required.)

Regression in ba31b0103442ac891fb3cb98f316781254e366c3.

comment:2 by Dominique Bischof, 21 months ago

Owner: changed from nobody to Dominique Bischof
Status: newassigned

comment:3 by Jon Dufresne, 21 months ago

Cc: Jon Dufresne removed

comment:5 by Mariusz Felisiak, 21 months ago

Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 21 months ago

Resolution: fixed
Status: assignedclosed

In 17e08b21:

Fixed #34377 -- Fixed preserving query strings in AdminSite.catch_all_view().

Included full path when redirecting with append slash to include query
strings.

Regression in ba31b0103442ac891fb3cb98f316781254e366c3.

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