[Zope3-checkins] CVS: Zope3/src/zodb/code - patch.py:1.3

Jeremy Hylton jeremy@zope.com
Mon, 30 Dec 2002 14:20:04 -0500


Update of /cvs-repository/Zope3/src/zodb/code
In directory cvs.zope.org:/tmp/cvs-serv1740

Modified Files:
	patch.py 
Log Message:
Make cross-module imports of persistent classes work.


=== Zope3/src/zodb/code/patch.py 1.2 => 1.3 ===
--- Zope3/src/zodb/code/patch.py:1.2	Wed Dec 25 09:12:18 2002
+++ Zope3/src/zodb/code/patch.py	Mon Dec 30 14:20:03 2002
@@ -164,7 +164,19 @@
             self._pmemo[oid] = object
             return oid
         else:
-            return None
+            # If the object is a real persistent object, patch it by
+            # persistent id, too.  This case is specifically intended
+            # to catch persistent classes imported from other modules.
+            # They are classes, but can't be pickled as globals because
+            # pickle looks in sys.modules and the persistent import
+            # doesn't use sys.modules.
+            
+            # XXX Is this safe in all cases?
+            oid = getattr(object, "_p_oid", None)
+            if oid is None:
+                return None
+            self._pmemo[oid] = object
+            return oid
 
     def save_type(self, atype):
         if atype.__module__ == "__builtin__":