summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaƂ Pasternak <michal.dtz@gmail.com>2017-10-27 23:38:43 +0200
committerTim Graham <timograham@gmail.com>2017-11-01 15:12:18 -0400
commite554b72a2a5473f3f1e57a32565758757a9e8e87 (patch)
treec4925f372f8a3092a6c944c4a8fc23b295a9e42a
parent6e8508734b070b30db9259b64bb748fb2a5a1bfb (diff)
Fixed #28749 -- Added subquery support for ArrayField's __in lookup.
-rw-r--r--django/contrib/postgres/fields/array.py3
-rw-r--r--tests/postgres_tests/test_array.py9
2 files changed, 12 insertions, 0 deletions
diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py
index 5c9bb1b2ee..6a8fbd0e91 100644
--- a/django/contrib/postgres/fields/array.py
+++ b/django/contrib/postgres/fields/array.py
@@ -242,6 +242,9 @@ class ArrayLenTransform(Transform):
class ArrayInLookup(In):
def get_prep_lookup(self):
values = super().get_prep_lookup()
+ if hasattr(self.rhs, '_prepare'):
+ # Subqueries don't need further preparation.
+ return values
# In.process_rhs() expects values to be hashable, so convert lists
# to tuples.
prepared_values = []
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index 77ac049ce4..e2ad3e8dcc 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -176,6 +176,15 @@ class TestQuerying(PostgreSQLTestCase):
self.objs[:2]
)
+ def test_in_subquery(self):
+ IntegerArrayModel.objects.create(field=[2, 3])
+ self.assertSequenceEqual(
+ NullableIntegerArrayModel.objects.filter(
+ field__in=IntegerArrayModel.objects.all().values_list('field', flat=True)
+ ),
+ self.objs[2:3]
+ )
+
@unittest.expectedFailure
def test_in_including_F_object(self):
# This test asserts that Array objects passed to filters can be