[Django] #26707: QueryDict.fromkeys fails in mysterious ways

6 views
Skip to first unread message

Django

unread,
Jun 3, 2016, 6:50:04 PM6/3/16
to django-...@googlegroups.com
#26707: QueryDict.fromkeys fails in mysterious ways
----------------------------+----------------------------
Reporter: wimglenn | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: master
Severity: Normal | Keywords: http querydict
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+----------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26707>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 3, 2016, 6:57:46 PM6/3/16
to django-...@googlegroups.com
#26707: QueryDict.fromkeys fails in mysterious ways
--------------------------------+------------------------------------

Reporter: wimglenn | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: http querydict | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by carljm):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/26707#comment:1>

Django

unread,
Jun 3, 2016, 7:15:35 PM6/3/16
to django-...@googlegroups.com
#26707: QueryDict.fromkeys fails in mysterious ways
--------------------------------+------------------------------------

Reporter: wimglenn | Owner: nobody
Type: Bug | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: http querydict | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by wimglenn):

* has_patch: 0 => 1
* component: Utilities => HTTP handling


Comment:

https://github.com/django/django/pull/6715

--
Ticket URL: <https://code.djangoproject.com/ticket/26707#comment:2>

Django

unread,
Jun 4, 2016, 2:47:20 AM6/4/16
to django-...@googlegroups.com
#26707: QueryDict.fromkeys fails in mysterious ways
--------------------------------+------------------------------------

Reporter: wimglenn | Owner: nobody
Type: Bug | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: http querydict | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by phildini):

* needs_better_patch: 0 => 1


Comment:

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!

--
Ticket URL: <https://code.djangoproject.com/ticket/26707#comment:3>

Django

unread,
Jun 4, 2016, 2:59:57 AM6/4/16
to django-...@googlegroups.com
#26707: QueryDict.fromkeys fails in mysterious ways
--------------------------------+------------------------------------

Reporter: wimglenn | Owner: nobody
Type: Bug | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: http querydict | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by phildini):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26707#comment:4>

Django

unread,
Jun 4, 2016, 10:49:04 AM6/4/16
to django-...@googlegroups.com
#26707: Add a QueryDict.fromkeys() method
-------------------------------------+-------------------------------------

Reporter: wimglenn | Owner: nobody
Type: Bug | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: http querydict | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/26707#comment:5>

Django

unread,
Jun 6, 2016, 8:58:58 AM6/6/16
to django-...@googlegroups.com
#26707: Add a QueryDict.fromkeys() method
-------------------------------------+-------------------------------------
Reporter: wimglenn | Owner: nobody
Type: Bug | Status: closed

Component: HTTP handling | Version: master
Severity: Normal | Resolution: fixed

Keywords: http querydict | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"5ebebd1159b4bacfce1999e41831081679b6f35a" 5ebebd11]:
{{{
#!CommitTicketReference repository=""
revision="5ebebd1159b4bacfce1999e41831081679b6f35a"
Fixed #26707 -- Added QueryDict.fromkeys()
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26707#comment:6>

Reply all
Reply to author
Forward
0 new messages