Opened 4 years ago

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

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by Tim Graham

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 Changed 4 years ago by Larry Martell

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.

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

Changed 4 years ago by Tim Graham

Attachment: 27107-test.diff added

comment:3 Changed 4 years ago by Tim Graham

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

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

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 4 years ago by Larry Martell (previous) (diff)

comment:5 Changed 4 years ago by Tim Graham

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

comment:6 in reply to:  5 Changed 4 years ago by Larry Martell

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 Changed 4 years ago by Tim Graham

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