Opened 3 years ago

Closed 3 years ago

#32929 closed Bug (fixed)

AsyncRequestFactory.get() ignores data parameter

Reported by: Pochang Lee Owned by: Pochang Lee
Component: Testing framework Version: dev
Severity: Normal Keywords: AsyncTestClient, AsyncRequestFactory
Cc: Andrew Godwin, Carlton Gibson 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

When passing data to AsyncRequestFactory.get(),
the resulting request.GET always gives an empty QueryDict

>>> request_factory = AsyncRequestFactory()
>>> request = request_factory.get('/somewhere/', {'var': '100'})
>>> request.GET
<QueryDict: {}>

while in synchronous

>>> request_factory = RequestFactory()
>>> request = request_factory.get('/somewhere/', {'var': '100'})
>>> request.GET
<QueryDict: {'var': ['100']}>

This also prevents AsyncClient.get() from passing GET parameters to view function.

Change History (5)

comment:1 by Pochang Lee, 3 years ago

Version: 3.2dev

comment:2 by Mariusz Felisiak, 3 years ago

Cc: Andrew Godwin Carlton Gibson added
Triage Stage: UnreviewedAccepted

Thanks for the report, good catch. I think the following should do the trick:

diff --git a/django/test/client.py b/django/test/client.py
index 4a0b6b45f4..b4c091aa5c 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -547,6 +547,8 @@ class AsyncRequestFactory(RequestFactory):
         follow = extra.pop('follow', None)
         if follow is not None:
             s['follow'] = follow
+        if query_string := extra.pop('QUERY_STRING', None):
+            s['query_string'] = query_string
         s['headers'] += [
             (key.lower().encode('ascii'), value.encode('latin1'))
             for key, value in extra.items()

Would you like to prepare a patch? (tests are also required).

in reply to:  2 comment:3 by Pochang Lee, 3 years ago

Has patch: set

Replying to Mariusz Felisiak:

Would you like to prepare a patch? (tests are also required).

Yes, I have submitted a pull request.

https://github.com/django/django/pull/14639

comment:4 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by GitHub <noreply@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In f6d3557a:

Fixed #32929 -- Fixed handling query strings in AsyncRequestFactory.

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