Commit fb7cd8f3 authored by Rob Miller's avatar Rob Miller

don't fail when invalidating blobs for which readers and writers have not been

initialized (as can happen when making a deep copy of a blob object)
parent 6149d5ac
......@@ -88,7 +88,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
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()
......@@ -112,6 +116,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