[Django] #34377: AdminSite.catch_all_view() drops query string in redirects

3 views
Skip to first unread message

Django

unread,
Mar 1, 2023, 9:42:03 PM3/1/23
to django-...@googlegroups.com
#34377: AdminSite.catch_all_view() drops query string in redirects
-----------------------------------------+------------------------
Reporter: dbischof | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
#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

--
Ticket URL: <https://code.djangoproject.com/ticket/34377>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 1, 2023, 11:35:46 PM3/1/23
to django-...@googlegroups.com
#34377: AdminSite.catch_all_view() drops query string in redirects
-----------------------------------+------------------------------------
Reporter: Dominique Bischof | Owner: nobody

Type: Bug | Status: new
Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* 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>

Django

unread,
Mar 2, 2023, 12:39:36 PM3/2/23
to django-...@googlegroups.com
#34377: AdminSite.catch_all_view() drops query string in redirects
-------------------------------------+-------------------------------------
Reporter: Dominique Bischof | Owner: Dominique
| Bischof
Type: Bug | Status: assigned

Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Dominique Bischof):

* owner: nobody => Dominique Bischof
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34377#comment:2>

Django

unread,
Mar 2, 2023, 12:52:46 PM3/2/23
to django-...@googlegroups.com
#34377: AdminSite.catch_all_view() drops query string in redirects
-------------------------------------+-------------------------------------
Reporter: Dominique Bischof | Owner: Dominique
| Bischof
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jon Dufresne):

* cc: Jon Dufresne (removed)


--
Ticket URL: <https://code.djangoproject.com/ticket/34377#comment:3>

Django

unread,
Mar 2, 2023, 3:00:00 PM3/2/23
to django-...@googlegroups.com
#34377: AdminSite.catch_all_view() drops query string in redirects
-------------------------------------+-------------------------------------
Reporter: Dominique Bischof | Owner: Dominique
| Bischof
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Dominique Bischof):

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/16612

--
Ticket URL: <https://code.djangoproject.com/ticket/34377#comment:4>

Django

unread,
Mar 3, 2023, 2:21:03 AM3/3/23
to django-...@googlegroups.com
#34377: AdminSite.catch_all_view() drops query string in redirects
-------------------------------------+-------------------------------------
Reporter: Dominique Bischof | Owner: Dominique
| Bischof
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34377#comment:5>

Django

unread,
Mar 3, 2023, 2:55:36 AM3/3/23
to django-...@googlegroups.com
#34377: AdminSite.catch_all_view() drops query string in redirects
-------------------------------------+-------------------------------------
Reporter: Dominique Bischof | Owner: Dominique
| Bischof
Type: Bug | Status: closed
Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* 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>

Reply all
Reply to author
Forward
0 new messages