[Zodb-checkins] CVS: Zope/lib/python/ZODB - Connection.py:1.124

Jeremy Hylton jeremy at zope.com
Wed Feb 25 14:09:15 EST 2004


Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv13442

Modified Files:
	Connection.py 
Log Message:
Add deprecation warning for register() call with _p_oid is None.


=== Zope/lib/python/ZODB/Connection.py 1.123 => 1.124 ===
--- Zope/lib/python/ZODB/Connection.py:1.123	Wed Feb 25 06:30:16 2004
+++ Zope/lib/python/ZODB/Connection.py	Wed Feb 25 14:09:14 2004
@@ -19,6 +19,7 @@
 import sys
 import threading
 import itertools
+import warnings
 from time import time
 from utils import u64
 
@@ -84,6 +85,9 @@
     connection or the transaction the connection is registered with,
     the application should provide locking.
 
+    The Connection manages movement of objects in and out of object
+    storage.
+
     XXX We should document an intended API for using a Connection via
     multiple threads.
 
@@ -210,6 +214,7 @@
             raise TypeError("Only first-class persistent objects may be"
                             " added to a Connection.", obj)
         elif obj._p_jar is None:
+            assert obj._p_oid is None
             oid = obj._p_oid = self._storage.new_oid()
             obj._p_jar = self
             self._added[oid] = obj
@@ -496,8 +501,17 @@
         policy of one transaction manager for each thread.
         """
         assert object._p_jar is self
-        # XXX Figure out why this assert causes test failures
-        #assert object._p_oid is not None
+        if object._p_oid is not None:
+            # There is some old Zope code that assigns _p_jar
+            # directly.  That is no longer allowed, but we need to
+            # provide support for old code that still does it.
+            
+            # XXX The actual complaint here is that an object without
+            # an oid is being registered.  I can't think of any way to
+            # achieve that without assignment to _p_jar.  If there is
+            # a way, this will be a very confusing warning.
+            warnings.warn("Assigning to _p_jar is deprecated",
+                          PendingDeprecationWarning)
         self.getTransaction().register(object)
 
     def root(self):




More information about the Zodb-checkins mailing list