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
Migrate Plone site from Zope2 2.13 to Zope2 4.0b3.dev0 #205
Comments
Expect the same error you got for
Instances of these classes are stored in pickles in the ZODB. They have a constructor ( This behaviour is independent from the ZODB: >>> class A:
... def __init__(self, x):
... self.x = x
>>> a = A(42)
>>> import pickle
>>> pickle.dumps(a)
"(i__main__\nA\np0\n(dp1\nS'x'\np2\nI42\nsb." When trying to read this pickle in a different Python 2.7 interpreter you get: >>> class A(object):
... def __init__(self, x):
... self.x = x
...
>>> import pickle
>>> pickle.loads("(i__main__\nA\np0\n(dp1\nS'x'\np2\nI42\nsb.")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/pickle.py", line 1388, in loads
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 1076, in load_inst
self._instantiate(klass, self.marker())
File "/usr/lib/python2.7/pickle.py", line 1066, in _instantiate
value = klass(*args)
TypeError: in constructor for A: __init__() takes exactly 2 arguments (1 given) A solution could be to make the argument of >>> class A(object):
... def __init__(self, x=None):
... self.x = x
...
>>> import pickle
>>> a2 = pickle.loads("(i__main__\nA\np0\n(dp1\nS'x'\np2\nI42\nsb.")
>>> a2.x
42
>>> pickle.dumps(a2)
"ccopy_reg\n_reconstructor\np0\n(c__main__\nA\np1\nc__builtin__\nobject\np2\nNtp3\nRp4\n(dp5\nS'x'\np6\nI42\nsb."
>>> pickle.loads(pickle.dumps(a2)).x
42 The pickle changes by switching from old-style classes to new-style classes, but it can be read again. So this seems to be okay. |
…lass. If the instance was created before Zope 4.0b2 unpickling broke because in 4.0b2 all classes became new-style classes. Fixes #205.
Maybe there are other classes besides the ones mentioned in this ticket which have the same problem. |
@icemac thank you, |
I just try it, and it works, Thank you |
python version : 2.7.14
Steps to reproduce :
The text was updated successfully, but these errors were encountered: