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 16, 2021
1 parent 8df6c70 commit 9d0736b
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 @@ -41,6 +41,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 @@ -60,6 +63,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 @@ -153,7 +162,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 9d0736b

Please sign in to comment.