[Django] #20574: Django Client Put Method Data is not Send

33 views
Skip to first unread message

Django

unread,
Jun 7, 2013, 11:49:38 PM6/7/13
to django-...@googlegroups.com
#20574: Django Client Put Method Data is not Send
-----------------------------------+-------------------------------------
Reporter: edwinlunando | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Keywords: Test, Client, Put, Data
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+-------------------------------------
I want to test my REST API like this:


{{{
data = {
'access_token': access_token.token
}
response = self.client.put(reverse('api:update_user'), data)
}}}

The question is, how can I access my data or query string at request
object from my view? request.POST, request.GET, request.body, and
request.META QUERY_STRING is empty. After I looked into the client put
code like this.


{{{
def put(self, path, data='', content_type='application/octet-stream',
**extra):
"Construct a PUT request."
return self.generic('PUT', path, data, content_type, **extra)

def generic(self, method, path,
data='', content_type='application/octet-stream',
**extra):
parsed = urlparse(path)
data = force_bytes(data, settings.DEFAULT_CHARSET)
r = {
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': force_str(parsed[4]),
'REQUEST_METHOD': str(method),
}
if data:
r.update({
'CONTENT_LENGTH': len(data),
'CONTENT_TYPE': str(content_type),
'wsgi.input': FakePayload(data),
})
r.update(extra)
return self.request(**r)
}}}

The data parameter is not added to query string like get method like.

{{{
def get(self, path, data={}, **extra):
"Construct a GET request."

parsed = urlparse(path)
r = {
'CONTENT_TYPE': str('text/html; charset=utf-8'),
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': urlencode(data, doseq=True) or
force_str(parsed[4]),
'REQUEST_METHOD': str('GET'),
}
r.update(extra)
return self.request(**r)
}}}

So, I think the PUT and DELETE method should behave the same like GET and
POST method at client. The "'QUERY_STRING': urlencode(data, doseq=True)
or force_str(parsed[4])," should be used at PUT and DELETE method.

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

Django

unread,
Jun 8, 2013, 3:17:49 AM6/8/13
to django-...@googlegroups.com
#20574: Django Client Put Method Data is not Send
-------------------------------------+-------------------------------------

Reporter: edwinlunando | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Resolution:
Keywords: Test, Client, Put, | Triage Stage:
Data | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

`urlencode(data, doseq=True)` emulates HTML form submission in a browser,
which only makes sense for GET and POST since browsers only support these
two methods.

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

Django

unread,
Jun 8, 2013, 5:15:04 AM6/8/13
to django-...@googlegroups.com
#20574: Django Client Put Method Data is not Send
-------------------------------------+-------------------------------------

Reporter: edwinlunando | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Resolution:
Keywords: Test, Client, Put, | Triage Stage:
Data | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by edwinlunando):

Hmm. So, there is no possible way to access the data parameter?

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

Django

unread,
Jun 8, 2013, 7:55:05 PM6/8/13
to django-...@googlegroups.com
#20574: Django Client Put Method Data is not Send
-------------------------------------+-------------------------------------
Reporter: edwinlunando | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: master

Severity: Normal | Resolution:
Keywords: Test, Client, Put, | Triage Stage:
Data | Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by ogpcludi <sample@…>):

* needs_better_patch: 0 => 1
* component: Testing framework => contrib.admin
* needs_tests: 0 => 1
* version: 1.5 => master
* easy: 0 => 1
* needs_docs: 0 => 1
* has_patch: 0 => 1
* ui_ux: 0 => 1
* type: Bug => Uncategorized


Comment:

1

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

Django

unread,
Jun 8, 2013, 7:55:05 PM6/8/13
to django-...@googlegroups.com
#20574: Django Client Put Method Data is not Send
-------------------------------------+-------------------------------------
Reporter: edwinlunando | Owner: anonymous
Type: Uncategorized | Status: assigned

Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: Test, Client, Put, | Triage Stage:
Data | Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by ogpcludi <sample@…>):

* status: new => assigned


* needs_better_patch: 0 => 1
* component: Testing framework => contrib.admin
* needs_tests: 0 => 1
* version: 1.5 => master
* easy: 0 => 1

* owner: nobody => anonymous


* needs_docs: 0 => 1
* has_patch: 0 => 1
* ui_ux: 0 => 1
* type: Bug => Uncategorized


Comment:

1

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

Django

unread,
Jun 8, 2013, 8:09:53 PM6/8/13
to django-...@googlegroups.com
#20574: Django Client Put Method Data is not Send
-------------------------------------+-------------------------------------
Reporter: edwinlunando | Owner: anonymous
Type: Uncategorized | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: Test, Client, Put, | Triage Stage:
Data | Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by ogpcludi <sample@…>):

1

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

Django

unread,
Jun 10, 2013, 9:00:13 AM6/10/13
to django-...@googlegroups.com
#20574: Django Client Put Method Data is not Send
-------------------------------------+-------------------------------------

Reporter: edwinlunando | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Resolution:
Keywords: Test, Client, Put, | Triage Stage:
Data | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by edwinlunando):

Replying to [comment:1 aaugustin]:


> `urlencode(data, doseq=True)` emulates HTML form submission in a
browser, which only makes sense for GET and POST since browsers only
support these two methods.


Then, how can I use the put method to test my application? The put seems
not doing anything if I cannot access the data.

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

Django

unread,
Jun 14, 2013, 6:45:32 PM6/14/13
to django-...@googlegroups.com
#20574: Django Client Put Method Data is not Send
-------------------------------------+-------------------------------------

Reporter: edwinlunando | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Resolution:
Keywords: Test, Client, Put, | Triage Stage:
Data | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by merb):

you could access the data with request.body, but it isn't parsed.
https://docs.djangoproject.com/en/dev/ref/request-
response/#django.http.HttpRequest.body

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

Django

unread,
Jun 26, 2013, 12:24:15 PM6/26/13
to django-...@googlegroups.com
#20574: Django Client Put Method Data is not Send
-------------------------------------+-------------------------------------
Reporter: edwinlunando | Owner: nobody
Type: Bug | Status: closed

Component: Testing framework | Version: 1.5
Severity: Normal | Resolution:
Keywords: Test, Client, Put, | worksforme
Data | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bak1an):

* status: new => closed
* resolution: => worksforme


Comment:

Hi edwinlunando.

{{{
data = {
'access_token': access_token.token
}
response = self.client.put(reverse('api:update_user'), data)
}}}

In this case you should be able to find your data in `request.body`.


Please note that PUT and DELETE methods are not designed to transmit data
within query string, so setting it to `urlencode(data, doseq=True)` for
all requests will be not correct (but if you want it for some reason - you
can urlencode your data when building url for request, e.g.
`self.client.put(reverse('api:update_user')+'?'+urlencode(data,
doseq=True))`).

Also, here is kind of related ticket - #12635.


I'm closing this ticket as worksforme, but feel free to reopen if
`request.body` is really empty and you think that it is because of some
django's bug.

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

Reply all
Reply to author
Forward
0 new messages