Skip to content

Commit

Permalink
Add support for loadBeforeEx
Browse files Browse the repository at this point in the history
zc.zlibstorage wraps base storage and includes generic __getattr__
to forward all unknown attribute access to base:

https://github.com/zopefoundation/zc.zlibstorage/blob/6d5a3c75/src/zc/zlibstorage/__init__.py#L52-L53

But if base implements loadBeforeEx (zopefoundation/ZODB#323)
the following scenario is then possible:

ZODB sees that zlibstorage provides loadBeforeEx and loads data via
loadBeforeEx instead of loadBefore, but the data are loaded
not decompressed, and ZODB complains about "broken pickle".

-> let's fix this by explicitly wrapping loadBeforeEx if base storage
provides it.
  • Loading branch information
navytux committed Nov 11, 2021
1 parent 6d5a3c7 commit 5a3d125
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/zc/zlibstorage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def __init__(self, base, *args, **kw):
self._transform = lambda data: data
self._untransform = decompress

if hasattr(base, 'loadBeforeEx'):
self.loadBeforeEx = self._loadBeforeEx

for name in self.copied_methods:
v = getattr(base, name, None)
if v is not None:
Expand All @@ -59,6 +62,12 @@ def load(self, oid, version=''):
data, serial = self.base.load(oid, version)
return self._untransform(data), serial

def _loadBeforeEx(self, oid, tid):
data, serial = self.base.loadBeforeEx(oid, tid)
if data is not None:
data = self._untransform(data)
return data, serial

def loadBefore(self, oid, tid):
r = self.base.loadBefore(oid, tid)
if r is not None:
Expand Down Expand Up @@ -151,7 +160,7 @@ class ServerZlibStorage(ZlibStorage):
"""

copied_methods = ZlibStorage.copied_methods + (
'load', 'loadBefore', 'loadSerial', 'store', 'restore',
'load', 'loadBefore', 'loadBeforeEx', 'loadSerial', 'store', 'restore',
'iterator', 'storeBlob', 'restoreBlob', 'record_iternext',
)

Expand Down

0 comments on commit 5a3d125

Please sign in to comment.