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.4|
|Has patch:||no||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 (6)
comment:1 Changed 18 months ago by akaariai
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
comment:4 Changed 5 months ago by anonymous
- Resolution set to wontfix
- Status changed from new to closed
comment:5 Changed 5 months ago by anonymous
- Resolution wontfix deleted
- Status changed from closed to new