0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Refs #27624 -- Made QuerySet._prefetch_related_lookups immutable.

This commit is contained in:
Adam Chainz 2016-12-23 14:58:22 +00:00 committed by Tim Graham
parent b8741c0058
commit 6ebf8f9057

View File

@ -165,9 +165,9 @@ class QuerySet(object):
self._result_cache = None
self._sticky_filter = False
self._for_write = False
self._prefetch_related_lookups = []
self._prefetch_related_lookups = ()
self._prefetch_done = False
self._known_related_objects = {} # {rel_field, {pk: rel_obj}}
self._known_related_objects = {} # {rel_field: {pk: rel_obj}}
self._iterable_class = ModelIterable
self._fields = None
@ -863,9 +863,9 @@ class QuerySet(object):
"""
clone = self._clone()
if lookups == (None,):
clone._prefetch_related_lookups = []
clone._prefetch_related_lookups = ()
else:
clone._prefetch_related_lookups.extend(lookups)
clone._prefetch_related_lookups = clone._prefetch_related_lookups + lookups
return clone
def annotate(self, *args, **kwargs):
@ -1061,7 +1061,7 @@ class QuerySet(object):
query.filter_is_sticky = True
clone = self.__class__(model=self.model, query=query, using=self._db, hints=self._hints)
clone._for_write = self._for_write
clone._prefetch_related_lookups = self._prefetch_related_lookups[:]
clone._prefetch_related_lookups = self._prefetch_related_lookups
clone._known_related_objects = self._known_related_objects
clone._iterable_class = self._iterable_class
clone._fields = self._fields
@ -1543,13 +1543,13 @@ def prefetch_one_level(instances, prefetcher, lookup, level):
# later (happens in nested prefetch_related).
additional_lookups = [
copy.copy(additional_lookup) for additional_lookup
in getattr(rel_qs, '_prefetch_related_lookups', [])
in getattr(rel_qs, '_prefetch_related_lookups', ())
]
if additional_lookups:
# Don't need to clone because the manager should have given us a fresh
# instance, so we access an internal instead of using public interface
# for performance reasons.
rel_qs._prefetch_related_lookups = []
rel_qs._prefetch_related_lookups = ()
all_related_objects = list(rel_qs)