Opened 4 years ago

Closed 4 years ago

#32117 closed Uncategorized (invalid)

Aggregation doesnt work with Models, ordered by Meta subclass

Reported by: eloktev Owned by: Dede Dian
Component: Uncategorized Version: 3.1
Severity: Normal Keywords: aggregation, database, psycopg2
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by eloktev)

Hello,
Using aggregation methods with models, that have set 'ordering' in Meta subclass fails:

class M1 (models.Model)
    date = models.DateField()
    smth = models.IntegerField()    

    class Meta:
        ordeing = 'smth'

count_by_day_qs = M1.objects.values('date').annotate(c=models.Count('id')).values('date', 'c')

#Executes following query:
SELECT "m1"."date", COUNT("m1"."id") AS "c" FROM "m1" GROUP BY "m1"."date", "m1"."smth"

Change History (4)

comment:1 by eloktev, 4 years ago

Description: modified (diff)

comment:2 by eloktev, 4 years ago

Description: modified (diff)

comment:3 by Dede Dian, 4 years ago

Owner: changed from nobody to Dede Dian
Status: newassigned

comment:4 by Simon Charette, 4 years ago

Resolution: invalid
Status: assignedclosed

This is documented as a caveat of performing aggregation against a model with a defined Meta.ordering

https://docs.djangoproject.com/en/3.1/topics/db/aggregation/#interaction-with-default-ordering-or-order-by

Please TicketClosingReasons/UseSupportChannels before filling a ticket in the future.

Note: See TracTickets for help on using tickets.
Back to Top