summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_array.py
diff options
context:
space:
mode:
authorHannes Ljungberg <hannes.ljungberg@gmail.com>2020-11-26 09:30:50 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-11-26 09:36:00 +0100
commit755b3275525953a2c4145b8a95913d0fbb9982a4 (patch)
treedc6e73f6e532ca38491f194af9bd701e83ef0d1d /tests/postgres_tests/test_array.py
parentaade2b461acafd16cfc82449b3df88a0f1c1c197 (diff)
downloaddjango-755b3275525953a2c4145b8a95913d0fbb9982a4.tar.gz
Added test for ArrayField's __contains lookup with subqueries.
Diffstat (limited to 'tests/postgres_tests/test_array.py')
-rw-r--r--tests/postgres_tests/test_array.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index 822e61f4e4..4d6f302b91 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -9,7 +9,7 @@ from django.core import checks, exceptions, serializers, validators
from django.core.exceptions import FieldError
from django.core.management import call_command
from django.db import IntegrityError, connection, models
-from django.db.models.expressions import RawSQL
+from django.db.models.expressions import Exists, OuterRef, RawSQL
from django.db.models.functions import Cast
from django.test import TransactionTestCase, modify_settings, override_settings
from django.test.utils import isolate_apps
@@ -313,6 +313,19 @@ class TestQuerying(PostgreSQLTestCase):
self.objs[1:3]
)
+ def test_contains_subquery(self):
+ IntegerArrayModel.objects.create(field=[2, 3])
+ inner_qs = IntegerArrayModel.objects.values_list('field', flat=True)
+ self.assertSequenceEqual(
+ NullableIntegerArrayModel.objects.filter(field__contains=inner_qs[:1]),
+ self.objs[2:3],
+ )
+ inner_qs = IntegerArrayModel.objects.filter(field__contains=OuterRef('field'))
+ self.assertSequenceEqual(
+ NullableIntegerArrayModel.objects.filter(Exists(inner_qs)),
+ self.objs[1:3],
+ )
+
def test_icontains(self):
# Using the __icontains lookup with ArrayField is inefficient.
instance = CharArrayModel.objects.create(field=['FoO'])