#17371 closed Cleanup/optimization (fixed)
For DELETE requests TestClient encodes data as QUERY_STRING and forces an empty payload
Reported by: | Owned by: | Aymeric Augustin | |
---|---|---|---|
Component: | Testing framework | Version: | 1.3 |
Severity: | Normal | 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
The Test Client's delete method is too limited.
The http 1.1 rfc (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html) doesn't specify that a request body is not allowed for DELETE requests. In fact the method is more similar to POST's and PUT's then it is to GET's. However when making a DELETE request with the test client the data is encoded as the query_string and no request-body-payload is provided
(https://code.djangoproject.com/browser/django/trunk/django/test/client.py#L313).
I would personally make it behave the same way as POST's do, but I can imagine a lot of code may depend on the existing implementation.
Attachments (2)
Change History (10)
comment:1 by , 13 years ago
Component: | Uncategorized → Testing framework |
---|---|
Has patch: | set |
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
by , 13 years ago
Attachment: | 17371-wip.patch added |
---|
comment:3 by , 13 years ago
Owner: | changed from | to
---|
I'm quite sure we'll have to break backwards compatibility to obtain a consistent behavior of the TestClient on requests other than GET and POST. I intend to work on this after the 1.4 release.
comment:4 by , 12 years ago
Patch needs improvement: | unset |
---|
Here's a patch that removes specific behavior from the test client for non-web methods, ie. methods other than GET, HEAD and POST.
In recent discussions, there was a clear consensus about not treating PUT requests like POST requests in Django. For consistency this design decision should be reflected in the test client. The same argument applies to OPTIONS and DELETE.
This is a backwards incompatible change. What do you think?
Related: #10571
by , 12 years ago
Attachment: | 17371.patch added |
---|
comment:5 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:6 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Indeed, I don't think Django should do anything special for requests other than GET/HEAD and POST.
For GET and POST requests, Django provides decoded arguments in the
request.GET
andrequest.POST
dictionaries, because that's what browsers use. It makes sense for the test client to provide the reverse encoding. And HEAD is well defined as being the same thing as GET.For all other HTTP methods, including DELETE, Django won't process the request body, see #12635. So it would be more consistent if the test client didn't perform encoding — it currently does for PUT (like POST) and DELETE (like GET). See attached patch.
This patch probably breaks a bunch of tests, and I haven't decided what to do wrt. backwards compatibility yet. But I'm supporting the idea of making the test client more predictable.
See also #17360.