Commit ec2664cf authored by Jim Fulton's avatar Jim Fulton

Bug Fixed: Packing failed for databases containing cross-database references.

parent e035a7a5
...@@ -605,17 +605,14 @@ class ObjectReader: ...@@ -605,17 +605,14 @@ class ObjectReader:
obj.__setstate__(state) obj.__setstate__(state)
oid_loaders = {
'w': lambda oid: None,
}
def referencesf(p, oids=None): def referencesf(p, oids=None):
"""Return a list of object ids found in a pickle """Return a list of object ids found in a pickle
A list may be passed in, in which case, information is A list may be passed in, in which case, information is
appended to it. appended to it.
Weak references are not included. Only ordinary internal references are included.
Weak and multi-database references are not included.
""" """
refs = [] refs = []
...@@ -636,16 +633,10 @@ def referencesf(p, oids=None): ...@@ -636,16 +633,10 @@ def referencesf(p, oids=None):
elif isinstance(reference, str): elif isinstance(reference, str):
oid = reference oid = reference
else: else:
try: assert isinstance(reference, list)
reference_type, args = reference continue
except ValueError:
# weakref
continue
else:
oid = oid_loaders[reference_type](*args)
if oid: oids.append(oid)
oids.append(oid)
return oids return oids
...@@ -678,15 +669,9 @@ def get_refs(a_pickle): ...@@ -678,15 +669,9 @@ def get_refs(a_pickle):
elif isinstance(reference, str): elif isinstance(reference, str):
data = reference, None data = reference, None
else: else:
try: assert isinstance(reference, list)
reference_type, args = reference continue
except ValueError:
# weakref
continue
else:
data = oid_klass_loaders[reference_type](*args)
if data: result.append(data)
result.append(data)
return result return result
...@@ -38,6 +38,8 @@ from ZODB.POSException import ConflictError, StorageError ...@@ -38,6 +38,8 @@ from ZODB.POSException import ConflictError, StorageError
from ZODB.tests.MTStorage import TestThread from ZODB.tests.MTStorage import TestThread
import ZODB.tests.util
ZERO = '\0'*8 ZERO = '\0'*8
...@@ -311,6 +313,24 @@ class PackableStorage(PackableStorageBase): ...@@ -311,6 +313,24 @@ class PackableStorage(PackableStorageBase):
pass pass
it.close() it.close()
def checkPackWithMultiDatabaseReferences(self):
databases = {}
db = DB(self._storage, databases=databases, database_name='')
otherdb = ZODB.tests.util.DB(databases=databases, database_name='o')
conn = db.open()
root = conn.root()
root[1] = C()
transaction.commit()
del root[1]
transaction.commit()
root[2] = conn.get_connection('o').root()
transaction.commit()
db.pack(time.time()+1)
assert(len(self._storage) == 1)
class PackableUndoStorage(PackableStorageBase): class PackableUndoStorage(PackableStorageBase):
def checkPackAllRevisions(self): def checkPackAllRevisions(self):
...@@ -705,3 +725,4 @@ class ElapsedTimer: ...@@ -705,3 +725,4 @@ class ElapsedTimer:
def elapsed_millis(self): def elapsed_millis(self):
return int((time.time() - self.start_time) * 1000) return int((time.time() - self.start_time) * 1000)
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