updating QueryDict in another dict gives unexpected results.
I noticed a small "bug" in the QueryDict.
When I have an existing dict and want to add the get or postdata to it using my_dict.update(request.POST).
This results in a dict with all the values as lists. I can understand why the QueryDict might work that way, the same key could have multiple values. Except that the QueryDict
does some magic that when you iterate over it it returns the first item in the list.
This limitation should be documented, and maybe a function should be added to the QueryDict to turn it into a normal dict.
Change History
(11)
Triage Stage: |
Unreviewed → Accepted
|
Severity: |
→ Normal
|
Type: |
→ Bug
|
Easy pickings: |
unset
|
Owner: |
changed from nobody to Tomek Paczkowski
|
Status: |
new → assigned
|
UI/UX: |
unset
|
Has patch: |
set
|
Needs documentation: |
set
|
Needs documentation: |
unset
|
Keywords: |
dceu2011 added
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
This is an interesting discrepancy.
I'm inclined to agree with your analysis - my_dict.update(request.POST) should only update values - but it's out of our hands. The python internals dictate the behavior in this case.
Your workaround seems reasonable - i.e., add a dict() method to QueryDict (strictly, to MultiValueDict) that provides a dictionary of key-value pairs, rather than key-list pairs.