Opened 4 years ago

Closed 4 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@… 4 years ago.

Download all attachments as: .zip

Change History (3)

Changed 4 years ago by emdonahu@…

comment:1 Changed 4 years ago by anonymous

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset

comment:2 Changed 4 years ago by melinath

  • Resolution set to invalid
  • Status changed from new to closed

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