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 Carl Meyer, 8 years ago

Triage Stage: UnreviewedAccepted

comment:2 by wim glenn, 8 years ago

Component: UtilitiesHTTP handling
Has patch: set

comment:3 by Philip James, 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 Philip James, 8 years ago

Patch needs improvement: unset

comment:5 by Tim Graham, 8 years ago

Summary: QueryDict.fromkeys fails in mysterious waysAdd a QueryDict.fromkeys() method
Triage Stage: AcceptedReady for checkin

Looks good, pending a few cosmetic updates noted on the PR.

comment:6 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 5ebebd11:

Fixed #26707 -- Added QueryDict.fromkeys()

Note: See TracTickets for help on using tickets.
Back to Top