SVN: ZODB/trunk/src/ Warn rather than fail if DB.open is called with an empty version string.

Jim Fulton <[email protected]>
Newsgroups gmane.comp.python.zope.zodb.cvs
Message-ID <20090730183052.86B7094182__11405.4625541486$1248978667$gmane$org@cvs.zope.org>
Log message for revision 102381:
  Warn rather than fail if DB.open is called with an empty version string.
  

Changed:
  U   ZODB/trunk/src/CHANGES.txt
  U   ZODB/trunk/src/ZODB/DB.py
  U   ZODB/trunk/src/ZODB/tests/testDB.py

-=-
Modified: ZODB/trunk/src/CHANGES.txt
===================================================================
--- ZODB/trunk/src/CHANGES.txt	2009-07-30 18:19:19 UTC (rev 102380)
+++ ZODB/trunk/src/CHANGES.txt	2009-07-30 18:30:52 UTC (rev 102381)
@@ -30,6 +30,13 @@
 - BlobStorage was not compatible with MVCC storages because the
   wrappers were being removed by each database connection.  Fixed.
 
+Features added back
+-------------------
+
+- Warn rather than fail if DB.open is called with an empty version
+  string.
+
+
 3.9.0b2 (2009-06-11)
 ====================
 

Modified: ZODB/trunk/src/ZODB/DB.py
===================================================================
--- ZODB/trunk/src/ZODB/DB.py	2009-07-30 18:19:19 UTC (rev 102380)
+++ ZODB/trunk/src/ZODB/DB.py	2009-07-30 18:30:52 UTC (rev 102381)
@@ -14,8 +14,6 @@
 """Database objects
 """
 
-import warnings
-
 import cPickle
 import cStringIO
 import sys
@@ -24,6 +22,7 @@
 import datetime
 import calendar
 import time
+import warnings
 
 from ZODB.broken import find_global
 from ZODB.utils import z64
@@ -728,6 +727,15 @@
             raise ValueError(
                 'cannot open an historical connection in the future.')
 
+        if isinstance(transaction_manager, basestring):
+            if transaction_manager:
+                raise TypeError("Versions aren't supported.")
+            warnings.warn(
+                "A version string was passed to open.\n"
+                "The first argument is a transaction manager.",
+                DeprecationWarning, 2)
+            transaction_manager = None
+
         self._a()
         try:
             # result <- a connection

Modified: ZODB/trunk/src/ZODB/tests/testDB.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testDB.py	2009-07-30 18:19:19 UTC (rev 102380)
+++ ZODB/trunk/src/ZODB/tests/testDB.py	2009-07-30 18:30:52 UTC (rev 102381)
@@ -240,6 +240,23 @@
         >>> db.close()
         """
 
+def connection_allows_empty_version_for_idiots():
+    r"""
+    >>> import sys, StringIO
+    >>> stderr = sys.stderr
+    >>> sys.stderr = StringIO.StringIO()
+    >>> db = ZODB.DB('t.fs')
+    >>> c = db.open('')
+    >>> sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+    '...: DeprecationWarning: A version string was passed to
+    open.\nThe first argument is a transaction manager...
+
+    >>> sys.stderr = stderr
+    >>> c.root()
+    {}
+    >>> db.close()
+    """
+
 def test_suite():
     s = unittest.makeSuite(DBTests)
     s.addTest(doctest.DocTestSuite(
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.