[Django] #33132: TestClient doesn't follow redirects that only contain a query string correctly.

1 view
Skip to first unread message

Django

unread,
Sep 22, 2021, 8:54:54 AM9/22/21
to django-...@googlegroups.com
#33132: TestClient doesn't follow redirects that only contain a query string
correctly.
---------------------------------------------+------------------------
Reporter: Jaap Roes | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
While running a projects test suite on Django 4.0a1 (using Python 3.8)
some tests unexpectedly started failing.

We have a `FormView` that defines the `get_success_url` method as follows:

{{{
def get_success_url(self):
"""
Redirect to self
"""
success = urllib.parse.urlencode({'success': self.n_deleted})
return f'?{success}'
}}}

In actual browsers this results in a redirect to the original request's
path with the querystring attached. The Django TestClient behaved the same
way, but after the update to Django 4.0a1 it suddenly redirects to
`/?success=1`.

This seems to be caused by the fix for #32790

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

Django

unread,
Sep 22, 2021, 9:02:08 AM9/22/21
to django-...@googlegroups.com
#33132: TestClient doesn't follow redirects that only contain a query string
correctly.
-----------------------------------+--------------------------------------

Reporter: Jaap Roes | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Jaap Roes):

Looking at #32790 it seems that there should also be a check that
`url.netloc` isn't empty before setting `path` to `'/'`

--
Ticket URL: <https://code.djangoproject.com/ticket/33132#comment:1>

Django

unread,
Sep 22, 2021, 11:09:27 AM9/22/21
to django-...@googlegroups.com
#33132: TestClient doesn't follow redirects that only contain a query string
correctly.
-----------------------------------+------------------------------------

Reporter: Jaap Roes | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.0
Severity: Release blocker | 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 Carlton Gibson):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Hey Jaap — I didn't look in depth yet, but that sounds right. Do you want
to make a patch?
Thanks.

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

Django

unread,
Sep 22, 2021, 12:06:48 PM9/22/21
to django-...@googlegroups.com
#33132: TestClient doesn't follow redirects that only contain a query string
correctly.
-----------------------------------+-------------------------------------
Reporter: Jaap Roes | Owner: Jaap Roes
Type: Bug | Status: assigned

Component: Testing framework | Version: 4.0
Severity: Release blocker | 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 Jaap Roes):

* owner: nobody => Jaap Roes
* status: new => assigned


Comment:

I'll look into fixing this tomorrow

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

Django

unread,
Sep 23, 2021, 6:20:33 AM9/23/21
to django-...@googlegroups.com
#33132: TestClient doesn't follow redirects that only contain a query string
correctly.
-----------------------------------+-------------------------------------
Reporter: Jaap Roes | Owner: Jaap Roes
Type: Bug | Status: assigned
Component: Testing framework | Version: 4.0
Severity: Release blocker | 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 Jaap Roes):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/14884 PR]

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

Django

unread,
Sep 23, 2021, 9:44:19 AM9/23/21
to django-...@googlegroups.com
#33132: TestClient doesn't follow redirects that only contain a query string
correctly.
-------------------------------------+-------------------------------------

Reporter: Jaap Roes | Owner: Jaap Roes
Type: Bug | Status: assigned
Component: Testing framework | Version: 4.0
Severity: Release blocker | 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 Carlton Gibson):

* stage: Accepted => Ready for checkin


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

Django

unread,
Sep 24, 2021, 2:22:43 AM9/24/21
to django-...@googlegroups.com
#33132: TestClient doesn't follow redirects that only contain a query string
correctly.
-------------------------------------+-------------------------------------
Reporter: Jaap Roes | Owner: Jaap Roes
Type: Bug | Status: closed

Component: Testing framework | Version: 4.0
Severity: Release blocker | 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 Carlton Gibson <carlton@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"b1bf8c8a4ba04049dc19217bf0e876488a4fae3c" b1bf8c8a]:
{{{
#!CommitTicketReference repository=""
revision="b1bf8c8a4ba04049dc19217bf0e876488a4fae3c"
Fixed #33132 -- Fixed test client handling of querystring only redirects.

Regression in 1e5aa8e1c79252cc810af21294a6e945d11d37b3.
}}}

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

Django

unread,
Sep 24, 2021, 2:24:12 AM9/24/21
to django-...@googlegroups.com
#33132: TestClient doesn't follow redirects that only contain a query string
correctly.
-------------------------------------+-------------------------------------
Reporter: Jaap Roes | Owner: Jaap Roes
Type: Bug | Status: closed
Component: Testing framework | Version: 4.0
Severity: Release blocker | 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
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton.gibson@…>):

In [changeset:"5d36af6f6fe7766c1d2d3ea8c261ed22da2861af" 5d36af6f]:
{{{
#!CommitTicketReference repository=""
revision="5d36af6f6fe7766c1d2d3ea8c261ed22da2861af"
[4.0.x] Fixed #33132 -- Fixed test client handling of querystring only
redirects.

Regression in 1e5aa8e1c79252cc810af21294a6e945d11d37b3.

Backport of b1bf8c8a4ba04049dc19217bf0e876488a4fae3c from main
}}}

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

Reply all
Reply to author
Forward
0 new messages