#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 , 4 years ago
comment:2 by , 4 years ago
| Severity: | Normal → Release blocker |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
Hey Jaap — I didn't look in depth yet, but that sounds right. Do you want to make a patch?
Thanks.
comment:3 by , 4 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
I'll look into fixing this tomorrow
comment:5 by , 4 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Looking at #32790 it seems that there should also be a check that
url.netlocisn't empty before settingpathto'/'