[Django] #32929: AsyncRequestFactory.get() ignores data parameter

21 views
Skip to first unread message

Django

unread,
Jul 14, 2021, 10:34:09 PM7/14/21
to django-...@googlegroups.com
#32929: AsyncRequestFactory.get() ignores data parameter
-------------------------------------+-------------------------------------
Reporter: Pochang | Owner: Pochang Lee
Lee |
Type: Bug | Status: assigned
Component: Testing | Version: 3.2
framework | Keywords: AsyncTestClient,
Severity: Normal | AsyncRequestFactory
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

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

Django

unread,
Jul 14, 2021, 11:51:29 PM7/14/21
to django-...@googlegroups.com
#32929: AsyncRequestFactory.get() ignores data parameter
-------------------------------------+-------------------------------------
Reporter: Pochang Lee | Owner: Pochang

| Lee
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: AsyncTestClient, | Triage Stage:
AsyncRequestFactory | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Pochang Lee):

* version: 3.2 => dev


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

Django

unread,
Jul 15, 2021, 12:28:17 AM7/15/21
to django-...@googlegroups.com
#32929: AsyncRequestFactory.get() ignores data parameter
-------------------------------------+-------------------------------------
Reporter: Pochang Lee | Owner: Pochang

| Lee
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: AsyncTestClient, | Triage Stage: Accepted
AsyncRequestFactory |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Andrew Godwin, Carlton Gibson (added)
* stage: Unreviewed => Accepted


Comment:

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).

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

Django

unread,
Jul 15, 2021, 1:11:11 AM7/15/21
to django-...@googlegroups.com
#32929: AsyncRequestFactory.get() ignores data parameter
-------------------------------------+-------------------------------------
Reporter: Pochang Lee | Owner: Pochang

| Lee
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: AsyncTestClient, | Triage Stage: Accepted
AsyncRequestFactory |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Pochang Lee):

* has_patch: 0 => 1


Comment:

Replying to [comment:2 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

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

Django

unread,
Jul 15, 2021, 2:23:43 AM7/15/21
to django-...@googlegroups.com
#32929: AsyncRequestFactory.get() ignores data parameter
-------------------------------------+-------------------------------------
Reporter: Pochang Lee | Owner: Pochang

| Lee
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: AsyncTestClient, | Triage Stage: Ready for
AsyncRequestFactory | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


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

Django

unread,
Jul 15, 2021, 7:10:03 AM7/15/21
to django-...@googlegroups.com
#32929: AsyncRequestFactory.get() ignores data parameter
-------------------------------------+-------------------------------------
Reporter: Pochang Lee | Owner: Pochang
| Lee
Type: Bug | Status: closed

Component: Testing framework | Version: dev
Severity: Normal | Resolution: fixed

Keywords: AsyncTestClient, | Triage Stage: Ready for
AsyncRequestFactory | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

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


Comment:

In [changeset:"f6d3557aa13f33cfe2fa41094fc3d8a8b09c368c" f6d3557a]:
{{{
#!CommitTicketReference repository=""
revision="f6d3557aa13f33cfe2fa41094fc3d8a8b09c368c"
Fixed #32929 -- Fixed handling query strings in AsyncRequestFactory.
}}}

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

Reply all
Reply to author
Forward
0 new messages