#30655: len(queryset) and queryset.count() return different results.
-------------------------------------+-------------------------------------
     Reporter:  Sander Kleijwegt     |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by felixxm):

 * status:  new => closed
 * component:  Uncategorized => Database layer (models, ORM)
 * version:  2.2 => master
 * resolution:   => wontfix


Comment:

 Thanks for this report, but `QuerySet.count()` and `len(QuerySet)` can
 return different results.

 `count()` calls `SELECT COUNT(*)` (as described in
 [https://docs.djangoproject.com/en/2.2/ref/models/querysets/#count docs])
 without taking ordering into account, so in your case it returns the
 number of `Bar`'s. On the other hand `len()` evaluates query with ordering
 by related table (one to many) that's why it returns a different number.
 This behavior is in Django since 9c52d56f6f8a9cdafb231adf9f4110473099c9b5.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.e1365f33c7c1f0b15456dfb1b1fa7fe6%40djangoproject.com.

Reply via email to