Fixed #23396 -- Ensured ValueQuerySets are not checked by check_related_objects.

This commit is contained in:
Gabe Jackson 2014-09-02 15:30:53 +02:00 committed by Tim Graham
parent 3a34e45fdb
commit 0e16c3e3cd
3 changed files with 35 additions and 15 deletions

View file

@ -1094,21 +1094,17 @@ class Query(object):
Checks the type of object passed to query relations.
"""
if field.rel:
# testing for iterable of models
if hasattr(value, '__iter__'):
# Check if the iterable has a model attribute, if so
# it is likely something like a QuerySet.
if hasattr(value, 'model') and hasattr(value.model, '_meta'):
model = value.model
if not (model == opts.concrete_model
or opts.concrete_model in model._meta.get_parent_list()
or model in opts.get_parent_list()):
raise ValueError(
'Cannot use QuerySet for "%s": Use a QuerySet for "%s".' %
(model._meta.model_name, opts.object_name))
else:
for v in value:
self.check_query_object_type(v, opts)
# QuerySets implement is_compatible_query_object_type() to
# determine compatibility with the given field.
if hasattr(value, 'is_compatible_query_object_type'):
if not value.is_compatible_query_object_type(opts):
raise ValueError(
'Cannot use QuerySet for "%s": Use a QuerySet for "%s".' %
(value.model._meta.model_name, opts.object_name)
)
elif hasattr(value, '__iter__'):
for v in value:
self.check_query_object_type(v, opts)
else:
# expecting single model instance here
self.check_query_object_type(value, opts)