Commit 3d7e8e4d authored by Jim Fulton's avatar Jim Fulton

Fixed bug: Cross-database references to databases with empty names

weren't constructed properly.
parent 100a2198
...@@ -365,7 +365,7 @@ class ObjectWriter: ...@@ -365,7 +365,7 @@ class ObjectWriter:
# __getnewargs__ of its own, we'll lose the optimization # __getnewargs__ of its own, we'll lose the optimization
# of caching the class info. # of caching the class info.
if database_name: if database_name is not None:
return ['n', (database_name, oid)] return ['n', (database_name, oid)]
return oid return oid
...@@ -373,7 +373,7 @@ class ObjectWriter: ...@@ -373,7 +373,7 @@ class ObjectWriter:
# Note that we never get here for persistent classes. # Note that we never get here for persistent classes.
# We'll use direct refs for normal classes. # We'll use direct refs for normal classes.
if database_name: if database_name is not None:
return ['m', (database_name, oid, klass)] return ['m', (database_name, oid, klass)]
return oid, klass return oid, klass
......
...@@ -12,10 +12,42 @@ ...@@ -12,10 +12,42 @@
# #
############################################################################## ##############################################################################
from zope.testing.doctestunit import DocFileSuite import unittest
from zope.testing import doctest
__test__ = dict(
cross_db_refs_to_blank_db_name = """
There was a bug that caused bad refs to be generated is a database
name was blank.
>>> import ZODB.tests.util, persistent.mapping, transaction
>>> dbs = {}
>>> db1 = ZODB.tests.util.DB(database_name='', databases=dbs)
>>> db2 = ZODB.tests.util.DB(database_name='2', databases=dbs)
>>> conn1 = db1.open()
>>> conn2 = conn1.get_connection('2')
>>> for i in range(10):
... conn1.root()[i] = persistent.mapping.PersistentMapping()
... transaction.commit()
>>> conn2.root()[0] = conn1.root()[9]
>>> transaction.commit()
>>> conn2.root()._p_deactivate()
>>> conn2.root()[0] is conn1.root()[9]
True
>>> list(conn2.root()[0].keys())
[]
""",
)
def test_suite(): def test_suite():
return DocFileSuite("dbopen.txt", suite = unittest.TestSuite()
"multidb.txt", suite.addTest(doctest.DocFileSuite("dbopen.txt",
"synchronizers.txt", "multidb.txt",
) "synchronizers.txt",
))
suite.addTest(doctest.DocTestSuite())
return suite
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