Commit d5afef8e authored by Kirill Smelkov's avatar Kirill Smelkov

Fix breakage with zodbpickle >= 2

Starting from zodbpickle 2 its binary class does not allow users to set
arbitrary attributes and so

	binary._pack = bytes.__str__

fails with

	TypeError: can't set attributes of built-in/extension type 'zodbpickle.binary'

-> Fix it by explicitly checking for binary type on encoding instead of
setting binary._pack

See nexedi/slapos@27f574bc for pre-history.

/cc @jerome
parent 7f81ac2d
...@@ -13,13 +13,6 @@ ...@@ -13,13 +13,6 @@
############################################################################## ##############################################################################
def patch(): def patch():
# For msgpack & Py2/ZODB5.
try:
from zodbpickle import binary
binary._pack = bytes.__str__
except ImportError:
pass
from hashlib import md5 from hashlib import md5
from ZODB.Connection import Connection from ZODB.Connection import Connection
......
...@@ -18,6 +18,12 @@ import threading ...@@ -18,6 +18,12 @@ import threading
from functools import partial from functools import partial
from msgpack import packb from msgpack import packb
# For msgpack & Py2/ZODB5.
try:
from zodbpickle import binary
except ImportError:
class binary: pass # stub, binary should not be used
# The protocol version must be increased whenever upgrading a node may require # The protocol version must be increased whenever upgrading a node may require
# to upgrade other nodes. # to upgrade other nodes.
PROTOCOL_VERSION = 2 PROTOCOL_VERSION = 2
...@@ -52,6 +58,8 @@ def Unpacker(): ...@@ -52,6 +58,8 @@ def Unpacker():
iterable_types = set, tuple iterable_types = set, tuple
def default(obj): def default(obj):
if isinstance(obj, binary):
return obj.__str__()
try: try:
pack = obj._pack pack = obj._pack
except AttributeError: except AttributeError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment