From 036bb2b74afb50a71e7a945e8dd83499b603ac3a Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Sun, 7 Aug 2022 17:25:43 +0200 Subject: Fixed #33895 -- Fixed Case() crash with filters that match everything in When(). Thanks shukryzablah for the report. --- tests/expressions_case/tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/expressions_case/tests.py b/tests/expressions_case/tests.py index 9bad0b8747..221806c933 100644 --- a/tests/expressions_case/tests.py +++ b/tests/expressions_case/tests.py @@ -415,6 +415,16 @@ class CaseExpressionTests(TestCase): self.assertEqual(len(objects), CaseTestModel.objects.count()) self.assertTrue(all(obj.selected == "not selected" for obj in objects)) + def test_annotate_with_full_when(self): + objects = CaseTestModel.objects.annotate( + selected=Case( + When(~Q(pk__in=[]), then=Value("selected")), + default=Value("not selected"), + ) + ) + self.assertEqual(len(objects), CaseTestModel.objects.count()) + self.assertTrue(all(obj.selected == "selected" for obj in objects)) + def test_combined_expression(self): self.assertQuerysetEqual( CaseTestModel.objects.annotate( -- cgit v1.3