[Django] #28037: Inconsistency on QueryDict.items and documentation

8 views
Skip to first unread message

Django

unread,
Apr 6, 2017, 8:08:50 AM4/6/17
to django-...@googlegroups.com
#28037: Inconsistency on QueryDict.items and documentation
--------------------------------------------+------------------------
Reporter: Daniel F Moisset | Owner: nobody
Type: Uncategorized | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
There is a multiway inconsistency about the defined behaviour of
`QueryDict.items` (a similar thing happens for QueryDict.values`:

* The
[https://github.com/django/django/blob/master/django/utils/datastructures.py#L176
current implementation] actually returns a generator object (supporting
iteration only)
* The [https://docs.djangoproject.com/en/dev/ref/request-
response/#django.http.QueryDict.items documentation] says that it is "just
like the standard dictionary `items()` method", which in Python3 returns a
dict_items object (a [https://docs.python.org/3/library/stdtypes.html
#dictionary-view-objects view object], supporting set-like operations)
* But the example in the documentation 2 lines below that show a standard
python list (supporting indexing)

I see 2 different was to fix this:
1. Update the documentation and make explicit that a generator is returned
and that `Querydict` is a bit different than python dicts
2. Make `QueryDict` behave more like python by returning a set(). This
should not break backwards compatibility (a set is more general than a
generator), but use more memory (because the set must be fully built
instead of generated lazily)

I can provide patches for any of these options, but some core devs
recommended me getting an opinion of which is the right solution before
moving forward.

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

Django

unread,
Apr 6, 2017, 9:30:44 AM4/6/17
to django-...@googlegroups.com
#28037: Incorrect return type in QueryDict.items()/values() docs examples
----------------------------------+------------------------------------

Reporter: Daniel F Moisset | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Tim Graham):

* component: HTTP handling => Documentation
* stage: Unreviewed => Accepted
* type: Uncategorized => Bug


Old description:

> There is a multiway inconsistency about the defined behaviour of
> `QueryDict.items` (a similar thing happens for QueryDict.values`:
>
> * The
> [https://github.com/django/django/blob/master/django/utils/datastructures.py#L176
> current implementation] actually returns a generator object (supporting
> iteration only)
> * The [https://docs.djangoproject.com/en/dev/ref/request-
> response/#django.http.QueryDict.items documentation] says that it is
> "just like the standard dictionary `items()` method", which in Python3
> returns a dict_items object (a
> [https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects
> view object], supporting set-like operations)
> * But the example in the documentation 2 lines below that show a standard
> python list (supporting indexing)
>
> I see 2 different was to fix this:
> 1. Update the documentation and make explicit that a generator is
> returned and that `Querydict` is a bit different than python dicts
> 2. Make `QueryDict` behave more like python by returning a set(). This
> should not break backwards compatibility (a set is more general than a
> generator), but use more memory (because the set must be fully built
> instead of generated lazily)
>
> I can provide patches for any of these options, but some core devs
> recommended me getting an opinion of which is the right solution before
> moving forward.

New description:

There is an inconsistency about the defined behaviour of
`QueryDict.items()` (a similar thing happens for `QueryDict.values()`:

* The
[https://github.com/django/django/blob/master/django/utils/datastructures.py#L176
current implementation] actually returns a generator object (supporting
iteration only)
* The [https://docs.djangoproject.com/en/dev/ref/request-
response/#django.http.QueryDict.items documentation] says that it is "just
like the standard dictionary `items()` method", which in Python3 returns a
dict_items object (a [https://docs.python.org/3/library/stdtypes.html
#dictionary-view-objects view object], supporting set-like operations)
* But the example in the documentation 2 lines below that show a standard
python list (supporting indexing)

I see 2 different was to fix this:
1. Update the documentation and make explicit that a generator is returned
and that `Querydict` is a bit different than python dicts
2. Make `QueryDict` behave more like python by returning a set(). This
should not break backwards compatibility (a set is more general than a
generator), but use more memory (because the set must be fully built
instead of generated lazily)

I can provide patches for any of these options, but some core devs
recommended me getting an opinion of which is the right solution before
moving forward.

--

Comment:

Fixing the documentation looks like the correct way to proceed. The
current example shows the behavior on Python 2 was was
[https://github.com/django/django/commit/c716fe87821df00f9f03ecc761c914d1682591a2
#diff-f61cccc2a02c84d08ff7d28f87590566L199 to return a list].

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

Django

unread,
Apr 7, 2017, 4:35:58 AM4/7/17
to django-...@googlegroups.com
#28037: Incorrect return type in QueryDict.items()/values() docs examples
----------------------------------+------------------------------------
Reporter: Daniel F Moisset | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Daniel F Moisset):

* has_patch: 0 => 1


Comment:

Thank you, created a PR: https://github.com/django/django/pull/8320

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

Django

unread,
Apr 10, 2017, 10:31:36 AM4/10/17
to django-...@googlegroups.com
#28037: Incorrect return type in QueryDict.items()/values() docs examples
----------------------------------+------------------------------------
Reporter: Daniel F Moisset | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


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

Django

unread,
Apr 26, 2017, 9:07:22 PM4/26/17
to django-...@googlegroups.com
#28037: Incorrect return type in QueryDict.items()/values() docs examples
----------------------------------+------------------------------------
Reporter: Daniel F Moisset | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
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:"8ab7ce8558792f41637d6f87f2a8a117e169dd18" 8ab7ce85]:
{{{
#!CommitTicketReference repository=""
revision="8ab7ce8558792f41637d6f87f2a8a117e169dd18"
Fixed #28037 -- Clarified that QueryDict.items()/values() are generators.
}}}

Reply all
Reply to author
Forward
0 new messages