diff options
| author | ontowhee <82607723+ontowhee@users.noreply.github.com> | 2025-05-22 11:06:28 -0700 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-06-05 09:52:56 +0200 |
| commit | 68c9f7e0b79168007e6ba0139fd315d7c44ca8c9 (patch) | |
| tree | 00baee66b8bd0f4ece77a47ae2c04d1c228698e2 /tests/ordering | |
| parent | 51923c576a596ad00214e44028f9dee9748bce95 (diff) | |
Fixed #36407 -- Ensured default value is cast in Case expressions used in ORDER BY clause.
Thanks to deceze for the report. Thanks to Sarah Boyce for the test.
Thanks to Simon Charette for the investigation and review.
Diffstat (limited to 'tests/ordering')
| -rw-r--r-- | tests/ordering/tests.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/ordering/tests.py b/tests/ordering/tests.py index b29404ed77..421689b9fa 100644 --- a/tests/ordering/tests.py +++ b/tests/ordering/tests.py @@ -3,15 +3,18 @@ from operator import attrgetter from django.core.exceptions import FieldError from django.db.models import ( + Case, CharField, Count, DateTimeField, F, + IntegerField, Max, OrderBy, OuterRef, Subquery, Value, + When, ) from django.db.models.functions import Length, Upper from django.test import TestCase @@ -526,6 +529,17 @@ class OrderingTests(TestCase): 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_case_when_constant_value(self): + qs = Article.objects.order_by( + Case( + When(pk__in=[], then=Value(1)), + default=Value(0), + output_field=IntegerField(), + ).desc(), + "pk", + ) + self.assertSequenceEqual(qs, [self.a1, self.a2, self.a3, self.a4]) + def test_related_ordering_duplicate_table_reference(self): """ An ordering referencing a model with an ordering referencing a model |
