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
--
Ticket URL: <https://code.djangoproject.com/ticket/34377>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Carlton Gibson, Jon Dufresne (added)
* easy: 1 => 0
* stage: Unreviewed => Accepted
Comment:
Thanks for the report! Using `get_full_path()` should fix the issue:
{{{#!diff
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index 61be31d890..96c54e44ad 100644
--- a/django/contrib/admin/sites.py
+++ b/django/contrib/admin/sites.py
@@ -453,7 +453,7 @@ class AdminSite:
pass
else:
if getattr(match.func, "should_append_slash", True):
- return HttpResponsePermanentRedirect("%s/" %
request.path)
+ return
HttpResponsePermanentRedirect(request.get_full_path(force_append_slash=True))
raise Http404
def _build_app_dict(self, request, label=None):
}}}
Would you like to prepare PR via GitHub? (a regression test is required.)
Regression in ba31b0103442ac891fb3cb98f316781254e366c3.
--
Ticket URL: <https://code.djangoproject.com/ticket/34377#comment:1>
* owner: nobody => Dominique Bischof
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34377#comment:2>
* cc: Jon Dufresne (removed)
--
Ticket URL: <https://code.djangoproject.com/ticket/34377#comment:3>
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/16612
--
Ticket URL: <https://code.djangoproject.com/ticket/34377#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34377#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"17e08b2177928b02158997ee1c44d8322a2e6eb8" 17e08b21]:
{{{
#!CommitTicketReference repository=""
revision="17e08b2177928b02158997ee1c44d8322a2e6eb8"
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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34377#comment:6>