Prevent innapropriate order-based grouping on values+annotate queries
|Reported by:||Martin Chase||Owned by:|
|Component:||Database layer (models, ORM)||Version:|
|Cc:||Simon Charette||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
class Foo(models.Model): name = models.TextField() type = models.TextField() class Meta: ordering = ["name",] Foo.objects.all().values("type").annotate(models.Count("name"))
The above code fails to generate the expected result without adding
.order_by() to the query set.
Ticket #10574 called this fixed with documentation, but indicated a proper fix would be preferred once backwards compatibility wasn't an issue. Lest this fall off the radar for being closed, I am putting this ticket in for 2.0.
Change History (12)
comment:4 Changed 6 years ago by
|Patch needs improvement:||set|
|Triage Stage:||Unreviewed → Accepted|