diff options
author | Anssi Kääriäinen <akaariai@gmail.com> | 2013-10-11 00:12:10 +0300 |
---|---|---|
committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-11-07 14:29:50 +0200 |
commit | b1b04df06522b092a9b4768d2d61c52956e00eca (patch) | |
tree | 8187a7830e3bcaf5e7cfb354230dcdd39b19e9b3 /tests/extra_regress | |
parent | ccbba98131ace3beb43790c65e8f4eee94e9631c (diff) | |
download | django-b1b04df06522b092a9b4768d2d61c52956e00eca.tar.gz |
Fixed #20600 -- ordered distinct(*fields) in subqueries
Diffstat (limited to 'tests/extra_regress')
-rw-r--r-- | tests/extra_regress/tests.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/extra_regress/tests.py b/tests/extra_regress/tests.py index 3b40361750..e9954add9b 100644 --- a/tests/extra_regress/tests.py +++ b/tests/extra_regress/tests.py @@ -347,3 +347,19 @@ class ExtraRegressTests(TestCase): ['<TestObject: TestObject: a,a,a>', '<TestObject: TestObject: b,a,a>'], ordered=False ) + + def test_extra_values_distinct_ordering(self): + t1 = TestObject.objects.create(first='a', second='a', third='a') + t2 = TestObject.objects.create(first='a', second='b', third='b') + qs = TestObject.objects.extra( + select={'second_extra': 'second'} + ).values_list('id', flat=True).distinct() + self.assertQuerysetEqual( + qs.order_by('second_extra'), [t1.pk, t2.pk], lambda x: x) + self.assertQuerysetEqual( + qs.order_by('-second_extra'), [t2.pk, t1.pk], lambda x: x) + # Note: the extra ordering must appear in select clause, so we get two + # non-distinct results here (this is on purpose, see #7070). + self.assertQuerysetEqual( + qs.order_by('-second_extra').values_list('first', flat=True), + ['a', 'a'], lambda x: x) |