Opened 7 years ago

Closed 7 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


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

Attachments (1)

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

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by emdonahu@…

Attachment: ticket16235.diff added

comment:1 Changed 7 years ago by anonymous

Needs tests: set

comment:2 Changed 7 years ago by Stephen Burrows

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