[Django] #24190: "Don’t use len() on QuerySets" is too strong.

22 views
Skip to first unread message

Django

unread,
Jan 20, 2015, 10:19:26 AM1/20/15
to django-...@googlegroups.com
#24190: "Don’t use len() on QuerySets" is too strong.
--------------------------------------+--------------------
Reporter: collinanderson | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
I've seen people write code like:
{{{
qs = Model.objects.filter(a=b)
if qs.count() >= 1:
for q in qs:
# do something with q
}}}
They think the that ".count()" call is more efficient, but it actually
makes it slower. I asked the person about it they said: "the docs say
don't use len() on querysets".

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

Django

unread,
Jan 20, 2015, 10:23:29 AM1/20/15
to django-...@googlegroups.com
#24190: "Don’t use len() on QuerySets" is too strong.
-------------------------------------+-------------------------------------
Reporter: collinanderson | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_docs: => 0
* has_patch: 0 => 1
* needs_tests: => 0
* needs_better_patch: => 0


Comment:

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

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

Django

unread,
Jan 22, 2015, 8:26:48 PM1/22/15
to django-...@googlegroups.com
#24190: "Don’t use len() on QuerySets" is too strong.
--------------------------------------+------------------------------------

Reporter: collinanderson | Owner: nobody
Type: Cleanup/optimization | 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 timgraham):

* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted


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

Django

unread,
Jan 24, 2015, 8:27:30 AM1/24/15
to django-...@googlegroups.com
#24190: "Don’t use len() on QuerySets" is too strong.
-------------------------------------+-------------------------------------
Reporter: collinanderson | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | 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 raulcd):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


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

Django

unread,
Jan 24, 2015, 10:18:16 AM1/24/15
to django-...@googlegroups.com
#24190: "Don’t use len() on QuerySets" is too strong.
-------------------------------------+-------------------------------------
Reporter: collinanderson | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

Keywords: | 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:"ee23e03637aa8b82311f93b0a660574a0512891a"]:
{{{
#!CommitTicketReference repository=""
revision="ee23e03637aa8b82311f93b0a660574a0512891a"
Fixed #24190 -- Clarified len(queryset)
}}}

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

Django

unread,
Jan 24, 2015, 10:18:30 AM1/24/15
to django-...@googlegroups.com
#24190: "Don’t use len() on QuerySets" is too strong.
-------------------------------------+-------------------------------------
Reporter: collinanderson | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: master

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"09e8985f25ddd901a3678d4b34878d6c631b0cea"]:
{{{
#!CommitTicketReference repository=""
revision="09e8985f25ddd901a3678d4b34878d6c631b0cea"
[1.8.x] Fixed #24190 -- Clarified len(queryset)

Backport of ee23e03637aa8b82311f93b0a660574a0512891a from master
}}}

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

Django

unread,
Jan 24, 2015, 10:18:36 AM1/24/15
to django-...@googlegroups.com
#24190: "Don’t use len() on QuerySets" is too strong.
-------------------------------------+-------------------------------------
Reporter: collinanderson | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: master

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"6dc6ec218860e4d4c5c1833c9b8607c4014c85d7"]:
{{{
#!CommitTicketReference repository=""
revision="6dc6ec218860e4d4c5c1833c9b8607c4014c85d7"
[1.7.x] Fixed #24190 -- Clarified len(queryset)

Backport of ee23e03637aa8b82311f93b0a660574a0512891a from master
}}}

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

Reply all
Reply to author
Forward
0 new messages