Skip to content

Commit

Permalink
Try to push persistentclass along
Browse files Browse the repository at this point in the history
Problem: in Python 2 object lives in sys.modules['__builtin__'].  In
Python 3 it lives in sys.modules['builtins'].  When we pickle object in
Python 2 and try to load it in Python 3, we end up getting a Broken
object placeholder because sys.modules['__builtin__'] is AWOL.

I'm not sure how persistentclass.txt manages to reproduce that purely in
Python 3, but that's what the new assertion failure I added reports.

Oh, I know: old pickle protocol!

    Python 3.3.0 (default, Sep 29 2012, 17:14:58)
    [GCC 4.7.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pickle
    >>> pickle.dumps(object)
    b'\x80\x03cbuiltins\nobject\nq\x00.'
    >>> pickle.dumps(object, 1)
    b'c__builtin__\nobject\nq\x00.'
    >>> pickle.loads(_)
    <class 'object'>

We need to find the mapping layer that handles __builtin__ in Python
3.3's pickle and make sure our own ZODB.broken.find_global can do the
same.
  • Loading branch information
mgedmin committed Feb 20, 2013
1 parent 9f93b7f commit abad361
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ZODB/persistentclass.py
Expand Up @@ -191,7 +191,10 @@ def __getstate__(self):
__getstate__ = _p_MethodDescr(__getstate__)

def __setstate__(self, state):
self.__bases__, cdict = state
bases, cdict = state
if self.__bases__ != bases:
# __getnewargs__ should've taken care of that
raise AssertionError(self.__bases__, '!=', bases)
cdict = dict([(k, v) for (k, v) in cdict.items()
if not k.startswith('_p_')])

Expand Down

0 comments on commit abad361

Please sign in to comment.