summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-04-24 16:07:07 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-04-24 16:07:07 +0000
commit8a4e1de8b0573ce4330f7690fe5e9d786265e237 (patch)
tree9c1e239511705477e67a422131f7e25dfc1b57bc /tests
parentdd0c5855e9dc0c88f99c004db544c34eb67cf499 (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/many_to_one/models.py4
-rw-r--r--tests/regressiontests/queries/models.py10
2 files changed, 10 insertions, 4 deletions
diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py
index d2c8e87fc1..6616f8b55e 100644
--- a/tests/modeltests/many_to_one/models.py
+++ b/tests/modeltests/many_to_one/models.py
@@ -250,9 +250,9 @@ FieldError: Cannot resolve keyword 'reporter_id' into field. Choices are: headli
>>> Reporter.objects.filter(article__reporter=r).distinct()
[<Reporter: John Smith>]
-# It's possible to use values() calls across many-to-one relations.
+# It's possible to use values() calls across many-to-one relations. (Note, too, that we clear the ordering here so as not to drag the 'headline' field into the columns being used to determine uniqueness.)
>>> d = {'reporter__first_name': u'John', 'reporter__last_name': u'Smith'}
->>> list(Article.objects.filter(reporter=r).distinct().values('reporter__first_name', 'reporter__last_name')) == [d]
+>>> list(Article.objects.filter(reporter=r).distinct().order_by().values('reporter__first_name', 'reporter__last_name')) == [d]
True
# If you delete a reporter, his articles will be deleted.
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'))
[<Item: 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