Opened 16 years ago

Closed 16 years ago

#9186 closed (invalid)

Trying to get distinct values when model has a default sort order only ends in tears

Reported by: Forest Bond Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This used to do what I'd expect:

PbxRecord.objects.values('extension').distinct()

But now it returns way too many values, because it generates this query:

SELECT DISTINCT `datastore_pbxrecord`.`extension`, `datastore_pbxrecord`.`id` FROM `datastore_pbxrecord` ORDER BY `datastore_pbxrecord`.`id` ASC

This is because the default ordering on the model is by id. I assume this broke with the merge of queryset refactor, although I don't know that for sure. I'm currently running on 1.0 beta 2.

Change History (1)

comment:1 by Malcolm Tredinnick, 16 years ago

Resolution: invalid
Status: newclosed

This is intended behaviour and required to generate correct SQL. See the documentation for an explanation (that was originally included in the queryset-refactor merge, was lost in the docs refactor and re-added after beta-2 and before 1.0-final).

If you don't want the default ordering, call order_by() explicitly to remove it.

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