Opened 13 years ago

Closed 13 years ago

#16235 closed Bug (invalid)

Test client flatens POST data

Reported by: emdonahu@… Owned by: nobody
Component: Testing framework Version: 1.3
Severity: Normal Keywords: test client, querydict
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Under normal production conditions, request.POST returns a QueryDict corresponding to the query parameters, like so:

<QueryDict: {u'my_key': [u'my_value']}>

However, when running a post request from the test client via

python manage.py test

the post data gets flattened into a single string that is unparsable by the QueryDict, resulting in this:

<QueryDict: {u"{'my_key': ['my_value']}": [u'']}> #the whole parameter dictionary is flattened into a string

Currently, the data dict is serialized by the smart_str function, which only seems to be intended for encoding strings. The result is an encoded but unformatted serialized post_data string that eventually reaches the QueryDict constructor, but does not present a format that QueryDict respects. If this not in fact the intended behavior, the most straight-forward fix would seem to be urlencoding the data dict prior to serialization. A patch representative of this suggestion is attached. For further presentation of the issue, refer to http://stackoverflow.com/questions/6315960/djangos-querydict-bizarre-behavior-bunches-post-dictionary-into-a-single-key.

Attachments (1)

ticket16235.diff (499 bytes ) - added by emdonahu@… 13 years ago.

Download all attachments as: .zip

Change History (3)

by emdonahu@…, 13 years ago

Attachment: ticket16235.diff added

comment:1 by anonymous, 13 years ago

Needs tests: set

comment:2 by Stephen Burrows, 13 years ago

Resolution: invalid
Status: newclosed

See my answer on stackoverflow - this is a usage issue, not a problem with django.

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