Opened 85 minutes ago

Last modified 70 minutes ago

#36966 assigned Bug

Test client using query_params raises ValueError when following redirect

Reported by: Marc Gibbons Owned by: Marc Gibbons
Component: Testing framework Version: 6.0
Severity: Normal Keywords:
Cc: Marc Gibbons Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When the test client is called with query_params and follow=True, a ValueError is raised when following the redirect.

_follow_redirect populates data from the redirect URL's query string via QueryDict(url.query). Since query_params from the original request is never reset, both data and query_params end up non-empty, triggering: ValueError: query_params and data arguments are mutually exclusive.

Ref: https://github.com/django/django/blob/35dab0ad9ee2ed23101420cb0f253deda2818191/django/test/client.py#L998

Reproduction

def test_follow_redirect_with_query_params(self):
    self.client.get("/redirect_view/", query_params={"next": "x"}, follow=True)  # this yells

Change History (1)

comment:1 by Marc Gibbons, 70 minutes ago

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