Model.__reduce__() includes cached lookups
|Reported by:||Patryk Zawadzki||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.6|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
If you try to pickle an object after accessing any of its related instances, its
__dict__ will contain references to those instances and will cause them to be pickled as part of your object.
Pickling them can cause additional instances to be traversed and can result in an unexpectedly large number of objects being included. These will be pickled/unpickled as a single chunk and I assume the unpickled instance will continue to use its cached instances which may lead to surprising results (values not reflecting current DB state).
Pickling additional instances can cause relation traversal to cache additional reverse lookups thus modifying an instance's
__dict__ while it is being pickled. This results in:
RuntimeError: dictionary changed size during iteration