Opened 8 years ago

Closed 8 years ago

#27107 closed Uncategorized (needsinfo)

setting request.encoding damages request.POST

Reported by: Larry Martell Owned by: nobody
Component: HTTP handling Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

(Pdb) print key
"u'right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png'"
(Pdb) type(request.POST[key])
<type 'unicode'>
(Pdb) request.encoding = "iso-8859-1"
(Pdb) type(request.POST[key])
* MultiValueDictKeyError:
"u'right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png'"

Attachments (1)

27107-test.diff (949 bytes ) - added by Tim Graham 8 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Tim Graham, 8 years ago

Component: UncategorizedHTTP handling

It might be expected behavior -- see how setting request.encoding clears existing GET/POST data. If you believe it's a bug could you include a test for tests/request/tests.py or at least a complete code snippet we can run to reproduce the issue?

comment:2 by Larry Martell, 8 years ago

OK, I didn't see that, so I guess it is expected.

Version 0, edited 8 years ago by Larry Martell (next)

by Tim Graham, 8 years ago

Attachment: 27107-test.diff added

comment:3 by Tim Graham, 8 years ago

I can't reproduce a crash with the attached tests. Can you provide more details to reproduce?

in reply to:  3 comment:4 by Larry Martell, 8 years ago

Replying to timgraham:

I can't reproduce a crash with the attached tests. Can you provide more details to reproduce?

I have a view that does this:

keys = request.POST.keys()
for key in keys:
    # do something with request.POST[key]

and when I added this line inside the for loop:

request.encoding = "iso-8859-1"

I got a MultiValueDictKeyError when I accessed request.POST[key]. When I debugged it I observed what I posted in my initial post.

Last edited 8 years ago by Larry Martell (previous) (diff)

comment:5 by Tim Graham, 8 years ago

Is it possible that the new encoding changes the name of the key?

in reply to:  5 comment:6 by Larry Martell, 8 years ago

Replying to timgraham:

Is it possible that the new encoding changes the name of the key?


Perhaps this is what is happening. But I cannot test that anymore, as we've moved on and changed the way the client sends the request, so I am not using POST.keys any more (I am using request.FILES now). I don't have easy access to the client code to change it back to test. Sorry.

comment:7 by Tim Graham, 8 years ago

Resolution: needsinfo
Status: newclosed

Ok, closing as "needsinfo" since it's unclear if there's a bug in Django.

I created a follow up ticket to add some missing tests I noticed while investigate: #27113.

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