Iterate over the full resultset of execute_sql(result_type=MULTI) when filtering by __in with a subquery

This ensures that it will work equivalently for lists (as returned when connection.features.can_use_chunked_reads is False) as for iterators, and means we don't need to worry about missing results if we ever receive a chunked resultset.
This commit is contained in:
Matt Westcott 2017-11-10 19:49:11 +00:00 committed by Karl Hobley
parent 0ac90f0d58
commit 39c9372e52

View file

@ -340,10 +340,8 @@ class Elasticsearch2SearchQuery(BaseSearchQuery):
if lookup == 'in':
if isinstance(value, Query):
db_alias = self.queryset._db or DEFAULT_DB_ALIAS
value = next(value.get_compiler(db_alias)
.execute_sql(result_type=MULTI))
value = [r[0] for r in value]
resultset = value.get_compiler(db_alias).execute_sql(result_type=MULTI)
value = [row[0] for chunk in resultset for row in chunk]
elif not isinstance(value, list):
value = list(value)