Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FrozenDict cannot be unpickled #104

Open
mlucool opened this issue Feb 10, 2020 · 1 comment
Open

FrozenDict cannot be unpickled #104

mlucool opened this issue Feb 10, 2020 · 1 comment

Comments

@mlucool
Copy link

mlucool commented Feb 10, 2020

Hi,

In python 3, FrozenDict can be pickled, but not unpickled (python2 does not have this issue):

$ python3 -c 'from vdom.frozendict import FrozenDict; from six.moves import cPickle; cPickle.loads(cPickle.dumps(FrozenDict(a=1), -1))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/python/python-3.7/std/lib64/python3.7/site-packages/vdom/frozendict.py", line 26, in __setitem__
    return self.__readonly__(super(FrozenDict, self).__setitem__, *args, **kwargs)
  File "/usr/local/python/python-3.7/std/lib64/python3.7/site-packages/vdom/frozendict.py", line 21, in __readonly__
    raise ValueError("Can not modify FrozenDict")
ValueError: Can not modify FrozenDict

I believe this is due to the reduce method. For example, this fixes it:

from vdom.frozendict import FrozenDict
def _reduce_vdom_frozendict(self):
    return (FrozenDict, (tuple(self.items()),))
FrozenDict.__reduce__ = _reduce_vdom_frozendict

I am happy to make a PR if you believe this is the right fix.

@mlucool
Copy link
Author

mlucool commented Jun 15, 2021

Bumping this as we still run into it sometimes. Would you be willing to accept a PR for this?

CC @captainsafia @rgbkrk @willingc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant