fix: dont clear _meta when caching doc (#17115)
fix: dont clear meta when caching doc
This commit is contained in:
parent
1a1f5cc9f9
commit
c6d8f3bc7f
1 changed files with 17 additions and 2 deletions
|
|
@ -123,8 +123,23 @@ class BaseDocument(object):
|
|||
return meta
|
||||
|
||||
def __getstate__(self):
|
||||
self._meta = None
|
||||
return self.__dict__
|
||||
"""
|
||||
Called when pickling.
|
||||
Returns a copy of `__dict__` excluding unpicklable values like `_meta`.
|
||||
|
||||
More info: https://docs.python.org/3/library/pickle.html#handling-stateful-objects
|
||||
"""
|
||||
|
||||
# Always use the dict.copy() method to avoid modifying the original state
|
||||
state = self.__dict__.copy()
|
||||
self.remove_unpicklable_values(state)
|
||||
|
||||
return state
|
||||
|
||||
def remove_unpicklable_values(self, state):
|
||||
"""Remove unpicklable values before pickling"""
|
||||
|
||||
state.pop("_meta", None)
|
||||
|
||||
def update(self, d):
|
||||
"""Update multiple fields of a doctype using a dictionary of key-value pairs.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue