[1.8.x] Fixed #24719 -- Restored the ability to use interators as queryset related object filters.

Backport of 9c2d8cde77 from master
This commit is contained in:
Aric Coady 2015-04-27 15:23:56 -07:00 committed by Tim Graham
parent c37eb3c870
commit b67bd1b483
3 changed files with 8 additions and 1 deletions

View File

@ -8,7 +8,7 @@ all about the internals of models in order to get the information it needs.
""" """
import copy import copy
import warnings import warnings
from collections import Mapping, OrderedDict from collections import Iterator, Mapping, OrderedDict
from itertools import chain, count, product from itertools import chain, count, product
from string import ascii_uppercase from string import ascii_uppercase
@ -1167,6 +1167,9 @@ class Query(object):
field, sources, opts, join_list, path = self.setup_joins( field, sources, opts, join_list, path = self.setup_joins(
parts, opts, alias, can_reuse=can_reuse, allow_many=allow_many) parts, opts, alias, can_reuse=can_reuse, allow_many=allow_many)
# Prevent iterator from being consumed by check_related_objects()
if isinstance(value, Iterator):
value = list(value)
self.check_related_objects(field, value, opts) self.check_related_objects(field, value, opts)
# split_exclude() needs to know which joins were generated for the # split_exclude() needs to know which joins were generated for the

View File

@ -69,6 +69,9 @@ Bugfixes
* Fixed a migration crash when applying migrations with model managers on * Fixed a migration crash when applying migrations with model managers on
Python 3 that were generated on Python 2 (:ticket:`24701`). Python 3 that were generated on Python 2 (:ticket:`24701`).
* Restored the ability to use iterators as queryset filter arguments
(:ticket:`24719`).
Optimizations Optimizations
============= =============

View File

@ -3520,6 +3520,7 @@ class RelatedLookupTypeTests(TestCase):
# child objects # child objects
self.assertQuerysetEqual(ObjectB.objects.filter(objecta__in=[self.coa]), []) self.assertQuerysetEqual(ObjectB.objects.filter(objecta__in=[self.coa]), [])
self.assertQuerysetEqual(ObjectB.objects.filter(objecta__in=[self.poa, self.coa]).order_by('name'), out_b) self.assertQuerysetEqual(ObjectB.objects.filter(objecta__in=[self.poa, self.coa]).order_by('name'), out_b)
self.assertQuerysetEqual(ObjectB.objects.filter(objecta__in=iter([self.poa, self.coa])).order_by('name'), out_b)
# parent objects # parent objects
self.assertQuerysetEqual(ObjectC.objects.exclude(childobjecta=self.oa), out_c) self.assertQuerysetEqual(ObjectC.objects.exclude(childobjecta=self.oa), out_c)