Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33132 closed Bug (fixed)

TestClient doesn't follow redirects that only contain a query string correctly.

Reported by: Jaap Roes Owned by: Jaap Roes
Component: Testing framework Version: 4.0
Severity: Release blocker Keywords:
Cc: 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

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

Change History (7)

comment:1 by Jaap Roes, 3 years ago

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

comment:2 by Carlton Gibson, 3 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

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

comment:3 by Jaap Roes, 3 years ago

Owner: changed from nobody to Jaap Roes
Status: newassigned

I'll look into fixing this tomorrow

comment:4 by Jaap Roes, 3 years ago

Has patch: set
Last edited 3 years ago by Jaap Roes (previous) (diff)

comment:5 by Carlton Gibson, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Carlton Gibson <carlton@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In b1bf8c8a:

Fixed #33132 -- Fixed test client handling of querystring only redirects.

Regression in 1e5aa8e1c79252cc810af21294a6e945d11d37b3.

comment:7 by Carlton Gibson <carlton.gibson@…>, 3 years ago

In 5d36af6f:

[4.0.x] Fixed #33132 -- Fixed test client handling of querystring only redirects.

Regression in 1e5aa8e1c79252cc810af21294a6e945d11d37b3.

Backport of b1bf8c8a4ba04049dc19217bf0e876488a4fae3c from main

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