Re: [Django] #32117: Aggregation doesnt work with Models, ordered by Meta subclass

5 views
Skip to first unread message

Django

unread,
Oct 17, 2020, 6:54:20 PM10/17/20
to django-...@googlegroups.com
#32117: Aggregation doesnt work with Models, ordered by Meta subclass
-------------------------------------+-------------------------------------
Reporter: eloktev | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Resolution:
Keywords: aggregation, | Triage Stage:
database, psycopg2 | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by eloktev:

Old description:

> 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')
> }}}}
> Returns executes following query:
> {{{{
> SELECT "m1"."date", COUNT("m1"."id") AS "c" FROM "m1" GROUP BY
> "m1"."date", "m1"."smth"
> }}}}

New description:

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')
}}}}
Returns executes following query:
{{{{
SELECT "m1"."date", COUNT("m1"."id") AS "c" FROM "m1" GROUP BY
"m1"."date", "m1"."smth"
}}}}

--

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

Django

unread,
Oct 17, 2020, 6:54:52 PM10/17/20
to django-...@googlegroups.com

Old description:

New description:

#Executes following query:


SELECT "m1"."date", COUNT("m1"."id") AS "c" FROM "m1" GROUP BY
"m1"."date", "m1"."smth"

--

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

Django

unread,
Oct 17, 2020, 10:39:43 PM10/17/20
to django-...@googlegroups.com
#32117: Aggregation doesnt work with Models, ordered by Meta subclass
-------------------------------------+-------------------------------------
Reporter: eloktev | Owner: Dede Dian
Type: Uncategorized | Status: assigned

Component: Uncategorized | Version: 3.1
Severity: Normal | Resolution:
Keywords: aggregation, | Triage Stage:
database, psycopg2 | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Dede Dian):

* owner: nobody => Dede Dian
* status: new => assigned


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

Django

unread,
Oct 18, 2020, 11:04:58 AM10/18/20
to django-...@googlegroups.com
#32117: Aggregation doesnt work with Models, ordered by Meta subclass
-------------------------------------+-------------------------------------
Reporter: eloktev | Owner: Dede Dian
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 3.1
Severity: Normal | Resolution: invalid

Keywords: aggregation, | Triage Stage:
database, psycopg2 | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: assigned => closed
* resolution: => invalid


Comment:

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.

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

Reply all
Reply to author
Forward
0 new messages