Opened 8 years ago
Closed 8 years ago
#26707 closed Bug (fixed)
Add a QueryDict.fromkeys() method
Reported by: | wim glenn | Owned by: | nobody |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | http querydict |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In django.http.QueryDict, we currently have the following weird behaviour and misleading error messages:
>>> QueryDict.fromkeys(['k1', 'k2']) AttributeError: This QueryDict instance is immutable
It is not possible to pass the mutable kwarg to the initialise in this way, either:
>>> QueryDict.fromkeys(['k1', 'k2'], mutable=True) TypeError: fromkeys() takes no keyword arguments
Django's querydict is-a dict, so the classmethod factory "fromkeys" should either
a) work, or
b) be explicitly disabled in the subclass, and documented as such
The relevant section in the docs ( https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.QueryDict ) says that:
QueryDict implements all the standard dictionary methods because it’s a subclass of dictionary. Exceptions are outlined here: ...
However, there is no mention about the fromkeys method.
Change History (6)
comment:1 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 8 years ago
Component: | Utilities → HTTP handling |
---|---|
Has patch: | set |
comment:3 by , 8 years ago
Patch needs improvement: | set |
---|
Noted in the PR that I think the current implementation needs more error handling, so I'm marking 'patch needs improvement'. Totally willing to be corrected on this!
comment:4 by , 8 years ago
Patch needs improvement: | unset |
---|
comment:5 by , 8 years ago
Summary: | QueryDict.fromkeys fails in mysterious ways → Add a QueryDict.fromkeys() method |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Looks good, pending a few cosmetic updates noted on the PR.
https://github.com/django/django/pull/6715