Commit e55c79e6 authored by Rob Miller's avatar Rob Miller

don't fail when trying to invalidate blobs for which readers and writers

have not been initialized (as can happen when doing a deep copy of a
blob object)
parent 66a6857a
......@@ -93,7 +93,7 @@ class Blob(persistent.Persistent):
# XXX should we warn of this? Maybe?
if self._p_changed is None:
return
for ref in self.readers+self.writers:
for ref in (self.readers or [])+(self.writers or []):
f = ref()
if f is not None:
f.close()
......
......@@ -17,6 +17,10 @@ import time
from zope.testing import doctest, renormalizing
import ZODB.tests.util
from StringIO import StringIO
from pickle import Pickler
from pickle import Unpickler
from ZODB import utils
from ZODB.FileStorage import FileStorage
from ZODB.blob import Blob, BlobStorage
......@@ -98,7 +102,7 @@ class ZODBBlobConfigTest(BlobConfigTestBase):
""")
class BlobUndoTests(unittest.TestCase):
class BlobTests(unittest.TestCase):
def setUp(self):
self.test_dir = tempfile.mkdtemp()
......@@ -111,6 +115,34 @@ class BlobUndoTests(unittest.TestCase):
os.chdir(self.here)
ZODB.blob.remove_committed_dir(self.test_dir)
class BlobCloneTests(BlobTests):
def testDeepCopyCanInvalidate(self):
"""
Tests regression for invalidation problems related to missing
readers and writers values in cloned objects (see
http://mail.zope.org/pipermail/zodb-dev/2008-August/012054.html)
"""
base_storage = FileStorage(self.storagefile)
blob_storage = BlobStorage(self.blob_dir, base_storage)
database = DB(blob_storage)
connection = database.open()
root = connection.root()
transaction.begin()
root['blob'] = Blob()
transaction.commit()
stream = StringIO()
p = Pickler(stream, 1)
p.dump(root['blob'])
u = Unpickler(stream)
stream.seek(0)
clone = u.load()
clone._p_invalidate()
class BlobUndoTests(BlobTests):
def testUndoWithoutPreviousVersion(self):
base_storage = FileStorage(self.storagefile)
blob_storage = BlobStorage(self.blob_dir, base_storage)
......
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