summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlberto Avila <albertoavila@gmail.com>2016-01-08 14:20:15 -0600
committerTim Graham <timograham@gmail.com>2016-01-13 08:38:07 -0500
commit5b3c66d8b64add684489f5010e43de73e7acdd04 (patch)
treeb152388915057b9391d03479c9efd9bbae76edfd /tests
parente625859f086375dac743fcdcb61890ae2dcefb93 (diff)
[1.8.x] Fixed #26071 -- Fixed crash with __in lookup in a Case expression.
Partial backport of afe0bb7b13bb8dc4370f32225238012c873b0ee3 from master.
Diffstat (limited to 'tests')
-rw-r--r--tests/expressions_case/tests.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/expressions_case/tests.py b/tests/expressions_case/tests.py
index 27aef931c0..de1859b368 100644
--- a/tests/expressions_case/tests.py
+++ b/tests/expressions_case/tests.py
@@ -8,7 +8,7 @@ from uuid import UUID
from django.core.exceptions import FieldError
from django.db import connection, models
-from django.db.models import F, Q, Max, Min, Value
+from django.db.models import F, Q, Max, Min, Sum, Value
from django.db.models.expressions import Case, When
from django.test import TestCase
from django.utils import six
@@ -119,6 +119,17 @@ class CaseExpressionTests(TestCase):
transform=attrgetter('integer', 'join_test')
)
+ def test_annotate_with_in_clause(self):
+ fk_rels = FKCaseTestModel.objects.filter(integer__in=[5])
+ self.assertQuerysetEqual(
+ CaseTestModel.objects.only('pk', 'integer').annotate(in_test=Sum(Case(
+ When(fk_rel__in=fk_rels, then=F('fk_rel__integer')),
+ default=Value(0),
+ ))).order_by('pk'),
+ [(1, 0), (2, 0), (3, 0), (2, 0), (3, 0), (3, 0), (4, 5)],
+ transform=attrgetter('integer', 'in_test')
+ )
+
def test_annotate_with_join_in_condition(self):
self.assertQuerysetEqual(
CaseTestModel.objects.annotate(join_test=Case(