[Django] #32162: Invalid 'Content-Length' header, and printing request body raises exception in POST requests using AsyncTestClient

94 views
Skip to first unread message

Django

unread,
Nov 2, 2020, 10:46:31 AM11/2/20
to django-...@googlegroups.com
#32162: Invalid 'Content-Length' header, and printing request body raises exception
in POST requests using AsyncTestClient
-------------------------------------+-------------------------------------
Reporter: tmiller02 | Owner: nobody
Type: Bug | Status: new
Component: | Version: 3.1
Uncategorized | 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 |
-------------------------------------+-------------------------------------
POST requests that are created using the AsyncTestClient do not seem to
have a valid 'Content-Length' header. In addition, attempting to print the
body of a POST request raises an exception (seemingly related to the
invalid 'Content-Length').

These issues can be demonstrated using AsyncRequestFactory:

{{{
>>> from django.test import AsyncRequestFactory
>>> rf = AsyncRequestFactory()
>>> post_request = rf.post('/submit/', {'foo': 'bar'})
>>> print(post_request.headers)
{'Host': 'testserver', 'Content-Length':
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
'Content-Type': 'multipart/form-data; boundary=BoUnDaRyStRiNg', 'Cookie':
''}
>>> print(post_request.body)
ValueError Traceback (most recent call
last)
/opt/my_project/venv/lib64/python3.6/site-packages/django/http/request.py
in body(self)
318 # Limit the maximum request data size that will be
handled in-memory.
319 if (settings.DATA_UPLOAD_MAX_MEMORY_SIZE is not None
and
--> 320 int(self.META.get('CONTENT_LENGTH') or 0) >
settings.DATA_UPLOAD_MAX_MEMORY_SIZE):
321 raise RequestDataTooBig('Request body exceeded
settings.DATA_UPLOAD_MAX_MEMORY_SIZE.')
322
ValueError: invalid literal for int() with base 10:
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
}}}

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

Django

unread,
Nov 2, 2020, 10:47:13 AM11/2/20
to django-...@googlegroups.com
#32162: Invalid 'Content-Length' header, and printing request body raises exception
in POST requests using AsyncTestClient
-------------------------------------+-------------------------------------
Reporter: tmiller02 | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 3.1
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 tmiller02):

* component: Uncategorized => Testing framework


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

Django

unread,
Nov 2, 2020, 2:09:06 PM11/2/20
to django-...@googlegroups.com
#32162: AsyncTestClient crashes on requests with JSON data.
-------------------------------------+-------------------------------------
Reporter: Tom Miller | Owner: patrick
Type: Bug | Status: assigned

Component: Testing framework | Version: 3.1
Severity: Release blocker | 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 Mariusz Felisiak):

* status: new => assigned
* severity: Normal => Release blocker
* cc: Andrew Godwin, Carlton Gibson (added)
* owner: nobody => patrick
* has_patch: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Thanks for the report!

[https://github.com/django/django/pull/13632 PR]

#32164 was closes as a duplicate.

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

Django

unread,
Nov 3, 2020, 2:16:14 AM11/3/20
to django-...@googlegroups.com
#32162: AsyncTestClient crashes on requests with JSON data.
-------------------------------------+-------------------------------------
Reporter: Tom Miller | Owner: patrick
Type: Bug | Status: assigned
Component: Testing framework | Version: 3.1
Severity: Release blocker | 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/32162#comment:3>

Django

unread,
Nov 3, 2020, 4:36:58 AM11/3/20
to django-...@googlegroups.com
#32162: AsyncTestClient crashes on requests with JSON data.
-------------------------------------+-------------------------------------
Reporter: Tom Miller | Owner: patrick
Type: Bug | Status: closed

Component: Testing framework | Version: 3.1
Severity: Release blocker | 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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"542b4b3ab44d33dfd9b00c22f624ee4aed6f7534" 542b4b3a]:
{{{
#!CommitTicketReference repository=""
revision="542b4b3ab44d33dfd9b00c22f624ee4aed6f7534"
Fixed #32162 -- Fixed setting Content-Length header in
AsyncRequestFactory.
}}}

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

Django

unread,
Nov 3, 2020, 4:36:58 AM11/3/20
to django-...@googlegroups.com
#32162: AsyncTestClient crashes on requests with JSON data.
-------------------------------------+-------------------------------------
Reporter: Tom Miller | Owner: patrick
Type: Bug | Status: closed
Component: Testing framework | Version: 3.1
Severity: Release blocker | 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 Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"bb74d2db98f4b2bdd2955ebf728545518a05be27" bb74d2db]:
{{{
#!CommitTicketReference repository=""
revision="bb74d2db98f4b2bdd2955ebf728545518a05be27"
[3.1.x] Fixed #32162 -- Fixed setting Content-Length header in
AsyncRequestFactory.

Backport of 542b4b3ab44d33dfd9b00c22f624ee4aed6f7534 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages