From 8a4e1de8b0573ce4330f7690fe5e9d786265e237 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Thu, 24 Apr 2008 16:07:07 +0000 Subject: queryset-refactor: Changed the way order_by() and distinct() interact. When using "select distinct" all ordering columns must be part of the output (select) columns. We were previously just throwing away ordering columns that weren't included, but there are some cases where they are needed and it's difficult to add them in manually. So now the default behaviour is to append any missing columns. This can affect the output of distinct() if complicated order_by() constructs are used, so the documentation has been updated with an explanation of what's going on there. Fixed #7070. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7455 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/queries/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tests/regressiontests') diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index d99e828c3b..f893ac6ad8 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -498,9 +498,15 @@ Bug #3037 >>> Item.objects.filter(Q(creator__name='a3', name='two')|Q(creator__name='a4', name='four')) [] -Bug #5321 +Bug #5321, #7070 + +Ordering columns must be included in the output columns. Note that this means +results that might otherwise be distinct are not (if there are multiple values +in the ordering cols), as in this example. This isn't a bug; it's a warning to +be careful with the selection of ordering columns. + >>> Note.objects.values('misc').distinct().order_by('note', '-misc') -[{'misc': u'foo'}, {'misc': u'bar'}] +[{'misc': u'foo'}, {'misc': u'bar'}, {'misc': u'foo'}] Bug #4358 If you don't pass any fields to values(), relation fields are returned as -- cgit v1.3