Using distinct([*fields]) filter on a foreign key produces an ordering error when the foreign key has a Meta ordering field.
|Reported by:||chrisedgemon@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.7-beta-2|
|Severity:||Release blocker||Keywords:||distinct, query|
|Cc:||charettes||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Description (last modified by charettes)
I tried to using a distinct filter like this: Appearance.objects.order_by('team').distinct('team'); this fails with the following Database Error: "DatabaseError: SELECT DISTINCT ON expressions must match initial ORDER BY expressions"
It is possible to work around this problem by using this modified filter: Appearance.objects.order_by('team__id').distinct('team__id').
Change History (16)
comment:1 Changed 4 years ago by akaariai
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
comment:9 Changed 2 years ago by timo
- Severity changed from Normal to Release blocker
- Version changed from 1.4 to 1.7-beta-2
comment:12 Changed 2 years ago by Simon Charette <charette.s@…>
- Resolution set to fixed
- Status changed from new to closed