#32828: Wrong .count() for GROUP BY on ordered queryset
-------------------------------------+-------------------------------------
               Reporter:  Maxim      |          Owner:  nobody
  Petrov                             |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 {{{#!python
 class Foo(models.Model):
     name = models.TextField()
     date = models.DateTimeField()

 queryset =
 Foo.objects.order_by("date").values("name").annotate(models.Count("name"))
 }}}

 For this queryset Django use date in GROUP BY:
 {{{#!sql
 SELECT "foo"."name", COUNT("foo"."name") AS "name__count" FROM "foo" GROUP
 BY "foo"."name", "foo"."date" ORDER BY "foo"."date" ASC
 }}}
 But `queryset.count()` doesn't use it:
 {{{#!sql
 SELECT COUNT(*) FROM (SELECT "foo"."name" AS Col1, COUNT("foo"."name") AS
 "name__count" FROM "foo" GROUP BY "foo"."name")
 }}}
 So `queryset.count()` isn't equal real queryset length.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32828>
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/054.5288ee8ccb83d89167273103c3ef1419%40djangoproject.com.

Reply via email to