#26434: Inconsistent results of QuerySet.count() when ordering is not a subset 
of
explicit grouping.
-------------------------------------+-------------------------------------
     Reporter:  kamandol             |                    Owner:  Michal
                                     |  Mládek
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  postgresql queryset  |             Triage Stage:  Accepted
  count annotate aggreagate          |
  order_by                           |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

 > Using order_by('...') on a column that is also used implicitly for
 grouping in an aggregation queryset is a misuse of the ORM AFAIK. So what
 should we do about it?

 I share your sentiment that a warning should be emitted but that likely
 warrant a separate ticket inspired by #14357, #32546 (there might be one
 already I just can't find it now).

 I think we should keep this one focused on making sure the right results
 are returned in the mean time as it's caused by an over-eager optimization
 (pruning an `ORDER BY` for performance reasons).

 The way things are currently setup the ''not quite correct'' example is
 wrong as the `order_by("name")` is elided when `count()` is called but not
 when the full query is materialized.

 The example you linked is about aggregate function annotations but
 [https://dryorm.xterm.info/ticket-26434 you'll notice that the gotcha is
 not honored when aggregation is used].
-- 
Ticket URL: <https://code.djangoproject.com/ticket/26434#comment:18>
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 visit 
https://groups.google.com/d/msgid/django-updates/01070196da58481e-f9480f5f-9fbe-42ca-8930-87b46e2f3645-000000%40eu-central-1.amazonses.com.

Reply via email to