mirror of
https://github.com/django/django.git
synced 2025-09-24 19:23:03 +00:00
Fixed #27499 -- Made Prefetches pickle without evaluating their QuerySet.
This commit is contained in:
parent
7dd315a46f
commit
e044026dce
2 changed files with 19 additions and 0 deletions
|
@ -1289,6 +1289,16 @@ class Prefetch(object):
|
|||
self.queryset = queryset
|
||||
self.to_attr = to_attr
|
||||
|
||||
def __getstate__(self):
|
||||
obj_dict = self.__dict__.copy()
|
||||
if self.queryset is not None:
|
||||
# Prevent the QuerySet from being evaluated
|
||||
obj_dict['queryset'] = self.queryset._clone(
|
||||
_result_cache=[],
|
||||
_prefetch_done=True,
|
||||
)
|
||||
return obj_dict
|
||||
|
||||
def add_prefix(self, prefix):
|
||||
self.prefetch_through = LOOKUP_SEP.join([prefix, self.prefetch_through])
|
||||
self.prefetch_to = LOOKUP_SEP.join([prefix, self.prefetch_to])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue