1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #31863 -- Prevented mutating model state by copies of model instances.

Regression in bfb746f983.
This commit is contained in:
Gert Burger
2020-08-07 10:02:29 +02:00
committed by Mariusz Felisiak
parent 63300f7e68
commit 94ea79be13
2 changed files with 19 additions and 1 deletions

View File

@@ -546,7 +546,10 @@ class Model(metaclass=ModelBase):
def __getstate__(self):
"""Hook to allow choosing the attributes to pickle."""
return self.__dict__
state = self.__dict__.copy()
state['_state'] = copy.copy(state['_state'])
state['_state'].fields_cache = state['_state'].fields_cache.copy()
return state
def __setstate__(self, state):
pickled_version = state.get(DJANGO_VERSION_PICKLE_KEY)