fix: dont clear _meta when caching doc (#17115)

fix: dont clear meta when caching doc
This commit is contained in:
Sagar Vora 2022-06-22 06:43:35 +00:00 committed by GitHub
parent 1a1f5cc9f9
commit c6d8f3bc7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.