Opened 3 years ago
Closed 3 years ago
#33204 closed New feature (wontfix)
Make MultiValueDict more consistent
Reported by: | Yaroslav Pankovych | Owned by: | nobody |
---|---|---|---|
Component: | HTTP handling | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Yaroslav Pankovych | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
I was working with query parameters and found that .pop()
and .get()
both have different logic.
I assume that .pop()
should be the same as .get()
, but the key should get deleted afterward.
Here's an example:
In [1]: from django.utils.datastructures import MultiValueDict In [2]: data = MultiValueDict({"name": ["Yaroslav", "Clara"], "age": [22, 32]}) In [3]: data.get("name") Out[3]: 'Clara' In [4]: data.pop("name") Out[4]: ['Yaroslav', 'Clara']
As you can see, we've got a single item for .get()
, and a list for .pop()
, which is confusing.
We should have all of that synced. .get()
with .getlist()
, and .pop()
with .poplist()
.
Here's how it looks like after I've done some changes:
In [4]: data.pop("name") Out[4]: 'Clara'
In [5]: data.poplist("name") Out[5]: ['Yaroslav', 'Clara']
This is breaking change probably.
Change History (2)
comment:1 by , 3 years ago
Cc: | added |
---|---|
Needs documentation: | set |
comment:2 by , 3 years ago
Component: | Core (Other) → HTTP handling |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Thanks for the suggestion, however I don't think it's worth breaking backwards compatibility. We need to reach a strong consensus on the DevelopersMailingList before moving it forward. Please follow the triaging guidelines with regards to wontfix tickets and take this to DevelopersMailingList.
https://github.com/django/django/pull/14945