diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-01-20 22:36:47 -0500 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-22 08:58:23 +0100 |
| commit | 1df0f998ae8d1626adaa9b807a43e4cbdfc590e2 (patch) | |
| tree | 92c8454bede2c8c3cb4cdf9b85f2890a0f448dd5 /tests | |
| parent | e306687a3a5507d59365ba9bf545010e5fd4b2a8 (diff) | |
[5.2.x] Fixed #36117 -- Raised ValueError when providing composite expressions to case / when.
Remove redundant Case and When.resolve_expression to delegate composite
expression support to BaseExpression.
Thanks Jacob Tyler Walls for the report and test.
Backport of 00c690efbc0b10f67924687f24a7b30397bf47d9 from main.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/composite_pk/test_filter.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/composite_pk/test_filter.py b/tests/composite_pk/test_filter.py index aa2d9ebe36..fe942b9e5b 100644 --- a/tests/composite_pk/test_filter.py +++ b/tests/composite_pk/test_filter.py @@ -1,4 +1,13 @@ -from django.db.models import F, FilteredRelation, OuterRef, Q, Subquery, TextField +from django.db.models import ( + Case, + F, + FilteredRelation, + OuterRef, + Q, + Subquery, + TextField, + When, +) from django.db.models.functions import Cast from django.db.models.lookups import Exact from django.test import TestCase @@ -409,6 +418,14 @@ class CompositePKFilterTests(TestCase): with self.assertRaisesMessage(ValueError, msg): Comment.objects.filter(text__gt=Cast(F("pk"), TextField())).count() + def test_filter_case_when(self): + msg = "When expression does not support composite primary keys." + with self.assertRaisesMessage(ValueError, msg): + Comment.objects.filter(text=Case(When(text="", then="pk"))) + msg = "Case expression does not support composite primary keys." + with self.assertRaisesMessage(ValueError, msg): + Comment.objects.filter(text=Case(When(text="", then="text"), default="pk")) + def test_outer_ref_pk(self): subquery = Subquery(Comment.objects.filter(pk=OuterRef("pk")).values("id")) tests = [ |
