Skip to content

Commit

Permalink
Fix unpickling POSError subclasses under PyPy. This fixes a bunch of …
Browse files Browse the repository at this point in the history
…'<Unprintable POSKeyError>' tests in ZEO.
  • Loading branch information
jamadden committed Apr 10, 2015
1 parent f230651 commit b25eb53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ZODB/DB.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def f(con, detail=detail, rc=rc, conn_no=conn_no):
# and we also want to pretend that doesn't exist.
# If we have no way to get a refcount, we return False to symbolize
# that. As opposed to None, this has the advantage of being usable
# as a number (0) in case clients depended on that
# as a number (0) in case clients depended on that.
detail.append({
'conn_no': cn,
'oid': oid,
Expand Down
10 changes: 10 additions & 0 deletions src/ZODB/POSException.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ def __reduce__(self):

return (_recon, (self.__class__, state))

def __setstate__(self, state):
# PyPy doesn't store the 'args' attribute in an instance's
# __dict__; instead, it uses what amounts to a slot. Because
# we customize the pickled representation to just be a dictionary,
# the args would then get lost, leading to unprintable exceptions
# and worse. Manually assign to args from the state to be sure
# this doesn't happen.
super(POSError,self).__setstate__(state)
self.args = state['args']

class POSKeyError(POSError, KeyError):
"""Key not found in database."""

Expand Down

0 comments on commit b25eb53

Please sign in to comment.