1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #30971 -- Prevented Query.resolve_lookup_value() from coercing list values to tuples.

Regression in 8a281aa7fe.
This commit is contained in:
George Marshall 2019-11-10 00:48:36 -08:00 committed by Mariusz Felisiak
parent b93a0e34d9
commit 8be79984dc
2 changed files with 11 additions and 15 deletions

View File

@ -1059,21 +1059,10 @@ class Query(BaseExpression):
elif isinstance(value, (list, tuple)):
# The items of the iterable may be expressions and therefore need
# to be resolved independently.
resolved_values = []
for sub_value in value:
if hasattr(sub_value, 'resolve_expression'):
if isinstance(sub_value, F):
resolved_values.append(sub_value.resolve_expression(
self, reuse=can_reuse, allow_joins=allow_joins,
simple_col=simple_col,
))
else:
resolved_values.append(sub_value.resolve_expression(
self, reuse=can_reuse, allow_joins=allow_joins,
))
else:
resolved_values.append(sub_value)
value = tuple(resolved_values)
return type(value)(
self.resolve_lookup_value(sub_value, can_reuse, allow_joins, simple_col)
for sub_value in value
)
return value
def solve_lookup_type(self, lookup):

View File

@ -113,3 +113,10 @@ class TestQuery(SimpleTestCase):
clone = query.clone()
clone.add_select_related(['note', 'creator__extra'])
self.assertEqual(query.select_related, {'creator': {}})
def test_iterable_lookup_value(self):
query = Query(Item)
where = query.build_where(Q(name=['a', 'b']))
name_exact = where.children[0]
self.assertIsInstance(name_exact, Exact)
self.assertEqual(name_exact.rhs, "['a', 'b']")