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)
Change History (8)
comment:1 by , 8 years ago
Component: | Uncategorized → HTTP handling |
---|
comment:2 by , 8 years ago
OK, I didn't see that, so I guess it is expected. But then I don't understand this from the docs:
Any subsequent attribute accesses (such as reading from GET or POST) will use the new encoding value.
by , 8 years ago
Attachment: | 27107-test.diff added |
---|
follow-up: 4 comment:3 by , 8 years ago
I can't reproduce a crash with the attached tests. Can you provide more details to reproduce?
comment:4 by , 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.
follow-up: 6 comment:5 by , 8 years ago
Is it possible that the new encoding changes the name of the key?
comment:6 by , 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 , 8 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
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.
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?