[Checkins] SVN: ZODB/trunk/src/ZODB/ Fixed bug: Cross-database references to databases with empty names

Jim Fulton jim at zope.com
Thu May 15 10:20:38 EDT 2008


Log message for revision 86774:
  Fixed bug: Cross-database references to databases with empty names
  weren't constructed properly.
  

Changed:
  U   ZODB/trunk/src/ZODB/serialize.py
  U   ZODB/trunk/src/ZODB/tests/test_doctest_files.py

-=-
Modified: ZODB/trunk/src/ZODB/serialize.py
===================================================================
--- ZODB/trunk/src/ZODB/serialize.py	2008-05-15 14:20:31 UTC (rev 86773)
+++ ZODB/trunk/src/ZODB/serialize.py	2008-05-15 14:20:34 UTC (rev 86774)
@@ -365,7 +365,7 @@
             # __getnewargs__ of its own, we'll lose the optimization
             # of caching the class info.
 
-            if database_name:
+            if database_name is not None:
                 return ['n', (database_name, oid)]
 
             return oid
@@ -373,7 +373,7 @@
         # Note that we never get here for persistent 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 oid, klass

Modified: ZODB/trunk/src/ZODB/tests/test_doctest_files.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/test_doctest_files.py	2008-05-15 14:20:31 UTC (rev 86773)
+++ ZODB/trunk/src/ZODB/tests/test_doctest_files.py	2008-05-15 14:20:34 UTC (rev 86774)
@@ -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():
-    return DocFileSuite("dbopen.txt",
-                        "multidb.txt",
-                        "synchronizers.txt",
-                        )
+    suite = unittest.TestSuite()
+    suite.addTest(doctest.DocFileSuite("dbopen.txt",
+                                       "multidb.txt",
+                                       "synchronizers.txt",
+                                       ))
+    suite.addTest(doctest.DocTestSuite())
+    return suite



More information about the Checkins mailing list