[Django] #31494: Test client discards query string when following 307 or 308 redirects

13 views
Skip to first unread message

Django

unread,
Apr 21, 2020, 9:14:25 AM4/21/20
to django-...@googlegroups.com
#31494: Test client discards query string when following 307 or 308 redirects
-------------------------------------+-------------------------------------
Reporter: Max Crowe | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Testing | Version: 3.0
framework | Keywords: test client
Severity: Normal | redirect
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
If an application uses an HTTP 307 or 308 response to redirect /foo/ to
/bar/?a=b, when the test client is instructed to follow redirects, the
ultimate request will be to /bar/ (with no query string). This is due to
the fact that the test client only examines the query portion of the
response URL if the HTTP status is not 307 or 308:

{{{#!python
if response.status_code in (HTTPStatus.TEMPORARY_REDIRECT,
HTTPStatus.PERMANENT_REDIRECT):
# Preserve request method post-redirect for 307/308 responses.
request_method = getattr(self,
response.request['REQUEST_METHOD'].lower())
else:
request_method = self.get
data = QueryDict(url.query)
content_type = None
}}}

The test client should respect query strings indicated in redirect URLs,
even if the request method is something other than GET or HEAD.

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

Django

unread,
May 13, 2020, 9:55:45 PM5/13/20
to django-...@googlegroups.com
#31494: Allow test Client to re-use query string for non-GET requests when
following 307/308 redirects.
-------------------------------------+-------------------------------------
Reporter: Max Crowe | Owner: Ahmad
| Abdallah
Type: New feature | Status: assigned
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: test client | Triage Stage: Accepted
redirect |
Has patch: 0 | Needs documentation: 0

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

* cc: Ahmad Abdallah (added)
* owner: nobody => Ahmad Abdallah
* status: new => assigned


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

Django

unread,
May 15, 2020, 2:00:45 PM5/15/20
to django-...@googlegroups.com
#31494: Allow test Client to re-use query string for non-GET requests when
following 307/308 redirects.
-------------------------------------+-------------------------------------

Reporter: Max Crowe | Owner: Ahmad
| Abdallah
Type: New feature | Status: assigned
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: test client | Triage Stage: Accepted
redirect |
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


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

Django

unread,
May 15, 2020, 2:16:14 PM5/15/20
to django-...@googlegroups.com
#31494: Allow test Client to re-use query string for non-GET requests when
following 307/308 redirects.
-------------------------------------+-------------------------------------

Reporter: Max Crowe | Owner: Ahmad
| Abdallah
Type: New feature | Status: assigned
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: test client | Triage Stage: Accepted
redirect |
Has patch: 0 | Needs documentation: 0

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

* has_patch: 1 => 0


Comment:

As stated on the PR, this patch is incorrect. Fixing it now.

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

Django

unread,
May 15, 2020, 2:54:18 PM5/15/20
to django-...@googlegroups.com
#31494: Allow test Client to re-use query string for non-GET requests when
following 307/308 redirects.
-------------------------------------+-------------------------------------

Reporter: Max Crowe | Owner: Ahmad
| Abdallah
Type: New feature | Status: assigned
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: test client | Triage Stage: Accepted
redirect |
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31494#comment:6>

Django

unread,
May 20, 2020, 7:17:47 AM5/20/20
to django-...@googlegroups.com
#31494: Allow test Client to re-use query string for non-GET requests when
following 307/308 redirects.
-------------------------------------+-------------------------------------

Reporter: Max Crowe | Owner: Ahmad
| Abdallah
Type: New feature | Status: assigned
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: test client | Triage Stage: Accepted
redirect |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31494#comment:7>

Django

unread,
May 26, 2020, 1:56:34 PM5/26/20
to django-...@googlegroups.com
#31494: Allow test Client to re-use query string for non-GET requests when
following 307/308 redirects.
-------------------------------------+-------------------------------------

Reporter: Max Crowe | Owner: Ahmad
| Abdallah
Type: New feature | Status: assigned
Component: Testing framework | Version: master

Severity: Normal | Resolution:
Keywords: test client | Triage Stage: Accepted
redirect |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ahmad A. Hussein):

* needs_better_patch: 1 => 0
* version: 3.0 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/31494#comment:8>

Django

unread,
May 27, 2020, 4:37:27 AM5/27/20
to django-...@googlegroups.com
#31494: Allow test Client to re-use query string for non-GET requests when
following 307/308 redirects.
-------------------------------------+-------------------------------------

Reporter: Max Crowe | Owner: Ahmad
| Abdallah
Type: New feature | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: test client | Triage Stage: Accepted
redirect |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"6425fd3124e50219ba0b6f545d1bf7edfb053a59" 6425fd3]:
{{{
#!CommitTicketReference repository=""
revision="6425fd3124e50219ba0b6f545d1bf7edfb053a59"
Refs #31494 -- Added test for query strings for GET/HEAD requests when
following HTTP 307/308 redirects in test client.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31494#comment:9>

Django

unread,
May 27, 2020, 4:37:27 AM5/27/20
to django-...@googlegroups.com
#31494: Allow test Client to re-use query string for non-GET requests when
following 307/308 redirects.
-------------------------------------+-------------------------------------

Reporter: Max Crowe | Owner: Ahmad
| Abdallah
Type: New feature | Status: closed

Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed

Keywords: test client | Triage Stage: Accepted
redirect |
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:"7c947f0f5a0539add9adf8c4e14726ea509e13ef" 7c947f0]:
{{{
#!CommitTicketReference repository=""
revision="7c947f0f5a0539add9adf8c4e14726ea509e13ef"
Fixed #31494 -- Preserved query strings when following HTTP 307/308
redirects in test client.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31494#comment:10>

Reply all
Reply to author
Forward
0 new messages