[Django] #20408: values_list(flat=True) returns ValuesListQuerySet, not list

38 views
Skip to first unread message

Django

unread,
May 15, 2013, 7:29:08 AM5/15/13
to django-...@googlegroups.com
#20408: values_list(flat=True) returns ValuesListQuerySet, not list
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.4
Component: Documentation | Keywords: values_list queryset
Severity: Normal | list
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
The documentation should be updated to clarify that the structure returned
by a values_list queryset with flat=True is not a plain list, but a
ValuesListQuerySet. Alternatively, the code should actually output a list.

I spent a while struggling to understand why I couldn't use the Python
x.count(y) function on the output of such a query before realizing that I
wasn't working with a Python list:

{{{
> rlist = Rpt.objects.values_list('status', flat=True)
> type(rlist)
django.db.models.query.ValuesListQuerySet
> rlist.count(1)
TypeError: count() takes exactly 1 argument (2 given)
> rlist2 = list(Rpt.objects.values_list('status', flat=True))
> rlist2.count(1)
6
}}}

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

Django

unread,
May 16, 2013, 12:48:59 PM5/16/13
to django-...@googlegroups.com
#20408: values_list(flat=True) returns ValuesListQuerySet, not list
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: values_list | Needs documentation: 0
queryset list | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by bmispelon):

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


Comment:

Sounds like a reasonable addition.

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

Django

unread,
May 17, 2013, 11:59:56 AM5/17/13
to django-...@googlegroups.com
#20408: values_list(flat=True) returns ValuesListQuerySet, not list
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: EvilDMP
Type: | Status: assigned
Cleanup/optimization | Version: 1.4

Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: values_list | Needs documentation: 0
queryset list | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by EvilDMP):

* status: new => assigned
* owner: nobody => EvilDMP


Comment:

I have tentatively reserved this ticket for first-time committers who take
part in the [https://dont-be-afraid-to-commit.readthedocs.org/ Don't be
afraid to commit workshop] at the [http://2013.djangocon.eu/ DjangoCon
Europe 2013] sprints on 18th and 19th May.

If you want to tackle this ticket before then, please '''don't''' let the
fact that it's assigned to me stop you. Feel free to re-assign it to
yourself and do whatever you like to it.

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

Django

unread,
May 18, 2013, 5:35:51 AM5/18/13
to django-...@googlegroups.com
#20408: values_list(flat=True) returns ValuesListQuerySet, not list
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: alextreme
Type: | Status: assigned
Cleanup/optimization | Version: 1.4

Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: values_list | Needs documentation: 0
queryset list | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by alextreme):

* owner: EvilDMP => alextreme


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

Django

unread,
May 18, 2013, 6:02:00 AM5/18/13
to django-...@googlegroups.com
#20408: values_list(flat=True) returns ValuesListQuerySet, not list
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: alextreme
Type: | Status: assigned
Cleanup/optimization | Version: 1.4

Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: values_list | Needs documentation: 0
queryset list | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0

Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by alextreme):

* has_patch: 0 => 1


Comment:

Added a patch to clarify the values_list() documentation.

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

Django

unread,
May 18, 2013, 6:35:11 AM5/18/13
to django-...@googlegroups.com
#20408: values_list(flat=True) returns ValuesListQuerySet, not list
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: alextreme
Type: | Status: assigned
Cleanup/optimization | Version: 1.4

Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: values_list | Needs documentation: 0
queryset list | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by bmispelon):

How about something like that:

Note that this method returns a VLQS which is an object that behaves like
a list. Most of the time this is enough, but if you require an actual
python
list object, you can simply call list() on it (which will evaluate the
queryset).

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

Django

unread,
May 18, 2013, 6:38:10 AM5/18/13
to django-...@googlegroups.com
#20408: values_list(flat=True) returns ValuesListQuerySet, not list
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: alextreme
Type: | Status: assigned
Cleanup/optimization | Version: 1.4

Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: values_list | Needs documentation: 0
queryset list | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by alextreme):

Thanks, the ticket has been updated.

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

Django

unread,
May 18, 2013, 6:39:35 AM5/18/13
to django-...@googlegroups.com
#20408: values_list(flat=True) returns ValuesListQuerySet, not list
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: alextreme
Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: values_list | checkin
queryset list | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by bmispelon):

* stage: Accepted => Ready for checkin


Comment:

Looks good. Thanks for the patch!

--
Ticket URL: <https://code.djangoproject.com/ticket/20408#comment:7>

Django

unread,
May 18, 2013, 6:46:23 AM5/18/13
to django-...@googlegroups.com
#20408: values_list(flat=True) returns ValuesListQuerySet, not list
-------------------------------------+-------------------------------------
Reporter: marktranchant | Owner: alextreme
Type: | Status: closed
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution: fixed

Severity: Normal | Triage Stage: Ready for
Keywords: values_list | checkin
queryset list | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by Aymeric Augustin <aymeric.augustin@…>):

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


Comment:

In [changeset:"7b85ef9dfb83bd2f2cde46b9836b9fd12a033b26"]:
{{{
#!CommitTicketReference repository=""
revision="7b85ef9dfb83bd2f2cde46b9836b9fd12a033b26"
Fixed #20408 -- Clarified that values_list() doesn't return a list.

Thanks marktranchant, bmispelon, and alextreme.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20408#comment:8>

Reply all
Reply to author
Forward
0 new messages