[Zodb-checkins] SVN: ZODB/branches/3.8/ Fixed a fairly serious problem that could lead to bad object

Jim Fulton jim at zope.com
Wed May 14 17:42:28 EDT 2008


Log message for revision 86762:
  Fixed a fairly serious problem that could lead to bad object
  references across databases when the referenced database has an empty
  name.
  

Changed:
  U   ZODB/branches/3.8/NEWS.txt
  U   ZODB/branches/3.8/src/ZODB/serialize.py
  U   ZODB/branches/3.8/src/ZODB/tests/test_doctest_files.py

-=-
Modified: ZODB/branches/3.8/NEWS.txt
===================================================================
--- ZODB/branches/3.8/NEWS.txt	2008-05-14 20:25:22 UTC (rev 86761)
+++ ZODB/branches/3.8/NEWS.txt	2008-05-14 21:42:28 UTC (rev 86762)
@@ -5,6 +5,9 @@
 
 Bugs Fixed:
 
+- (beta 3) Cross-database references to databases with empty names
+  weren't constructed properly.
+
 - (beta 2) The cache used an excessive amount of memory, causing applications
   with large caches to exhaust available memory. 
 

Modified: ZODB/branches/3.8/src/ZODB/serialize.py
===================================================================
--- ZODB/branches/3.8/src/ZODB/serialize.py	2008-05-14 20:25:22 UTC (rev 86761)
+++ ZODB/branches/3.8/src/ZODB/serialize.py	2008-05-14 21:42:28 UTC (rev 86762)
@@ -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 driect refs for normal classes.
 
-        if database_name:
+        if database_name is not None:
             return ['m', (database_name, oid, klass)]
 
         return oid, klass

Modified: ZODB/branches/3.8/src/ZODB/tests/test_doctest_files.py
===================================================================
--- ZODB/branches/3.8/src/ZODB/tests/test_doctest_files.py	2008-05-14 20:25:22 UTC (rev 86761)
+++ ZODB/branches/3.8/src/ZODB/tests/test_doctest_files.py	2008-05-14 21:42:28 UTC (rev 86762)
@@ -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 Zodb-checkins mailing list