diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-05-21 20:10:24 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-05-31 07:38:48 +0200 |
| commit | f6075fb333bae29ee213b050e91eaadef75496dd (patch) | |
| tree | af294fb3cefca5edc538fa3458963dbe9894cdbc /tests | |
| parent | cc80979f011c72f8b4b5f35a5a36f049bc07bf0e (diff) | |
Fixed #26192 -- Fixed crash of ordering by constants on PostgreSQL.
Thanks Simon Charette for the review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ordering/tests.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/tests/ordering/tests.py b/tests/ordering/tests.py index e5f56917d4..18c32d6d5f 100644 --- a/tests/ordering/tests.py +++ b/tests/ordering/tests.py @@ -405,17 +405,35 @@ class OrderingTests(TestCase): attrgetter("headline") ) - def test_order_by_annotated_constant_value(self): + def test_order_by_constant_value(self): + # Order by annotated constant from selected columns. qs = Article.objects.annotate( constant=Value('1', output_field=CharField()), ).order_by('constant', '-headline') self.assertSequenceEqual(qs, [self.a4, self.a3, self.a2, self.a1]) + # Order by annotated constant which is out of selected columns. + self.assertSequenceEqual( + qs.values_list('headline', flat=True), [ + 'Article 4', + 'Article 3', + 'Article 2', + 'Article 1', + ], + ) + # Order by constant. + qs = Article.objects.order_by(Value('1', output_field=CharField()), '-headline') + self.assertSequenceEqual(qs, [self.a4, self.a3, self.a2, self.a1]) def test_order_by_constant_value_without_output_field(self): msg = 'Cannot resolve expression type, unknown output_field' qs = Article.objects.annotate(constant=Value('1')).order_by('constant') - with self.assertRaisesMessage(FieldError, msg): - qs.first() + for ordered_qs in ( + qs, + qs.values('headline'), + Article.objects.order_by(Value('1')), + ): + with self.subTest(ordered_qs=ordered_qs), self.assertRaisesMessage(FieldError, msg): + ordered_qs.first() def test_related_ordering_duplicate_table_reference(self): """ |
