You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So the field value is lost when pickling. I found out that pickle uses __dict__ variable by default, and as this does not contain field data, it is not saved to the serialized form.
Using customized __getstate__() and __setstate__() methods I managed to make it work, I just had to make sure the _cache_key variable is preserved, as unpickling the object does not run __init__() and _cache_key is not created:
Does this seem to be a correct way to handle pickling? Also, is it necessary to pickle the _cache_key, or would it be ok to just initialize it to a new value? (Some kind of _init_cache_key() method would be a good addition in that case).
If this is a correct direction, I can make a pull request and test it with other Python versions. Support for JSON serializer would also be possible.
The text was updated successfully, but these errors were encountered:
Thanks for the 'getstate()' and 'setstate()' information.
I was using jsonmodels with python multiprocessing Pool.map and had problems with the copying of arguments, because of this very issue (pickle is used in the background).
I'm now using this hack (runtime patching of models.Base):
I found out that using pickle serializer does not seem to work with jsonmodels. Using this simple model as an example (using Python 2.7.10):
I'm using Python 2.7.10.
So the field value is lost when pickling. I found out that pickle uses
__dict__
variable by default, and as this does not contain field data, it is not saved to the serialized form.Using customized
__getstate__()
and__setstate__()
methods I managed to make it work, I just had to make sure the_cache_key
variable is preserved, as unpickling the object does not run__init__()
and_cache_key
is not created:Does this seem to be a correct way to handle pickling? Also, is it necessary to pickle the
_cache_key
, or would it be ok to just initialize it to a new value? (Some kind of_init_cache_key()
method would be a good addition in that case).If this is a correct direction, I can make a pull request and test it with other Python versions. Support for JSON serializer would also be possible.
The text was updated successfully, but these errors were encountered: