Opened 7 years ago

Closed 7 years ago

#9186 closed (invalid)

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

Reported by: forest 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: UI/UX:

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 Changed 7 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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