[Zodb-checkins] CVS: ZODB3/ZODB - FileStorage.py:1.135.8.7 POSException.py:1.20.6.3 serialize.py:1.1.2.4

Jeremy Hylton cvs-admin at zope.org
Thu Oct 30 15:17:27 EST 2003


Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv13588/ZODB

Modified Files:
      Tag: zodb33-devel-branch
	FileStorage.py POSException.py serialize.py 
Log Message:
Change ConflictError to include the name of the object's class.


=== ZODB3/ZODB/FileStorage.py 1.135.8.6 => 1.135.8.7 ===
--- ZODB3/ZODB/FileStorage.py:1.135.8.6	Tue Oct 28 16:28:32 2003
+++ ZODB3/ZODB/FileStorage.py	Thu Oct 30 15:16:55 2003
@@ -729,11 +729,13 @@
                             `oid`, locked_version)
 
                 if serial != oserial:
-                    data = self.tryToResolveConflict(oid, oserial, serial,
+                    rdata = self.tryToResolveConflict(oid, oserial, serial,
                                                      data)
-                    if data is None:
-                        raise POSException.ConflictError(oid=oid,
-                                                serials=(oserial, serial))
+                    if rdata is None:
+                        raise POSException.ConflictError(
+                            oid=oid, serials=(oserial, serial), data=data)
+                    else:
+                        data = rdata
             else:
                 oserial=serial
 


=== ZODB3/ZODB/POSException.py 1.20.6.2 => 1.20.6.3 ===
--- ZODB3/ZODB/POSException.py:1.20.6.2	Tue Jul  1 18:02:20 2003
+++ ZODB3/ZODB/POSException.py	Thu Oct 30 15:16:55 2003
@@ -51,13 +51,17 @@
         related to conflict.  The first is the revision of object that
         is in conflict, the second is the revision of that the current
         transaction read when it started.
+      data : string
+        The database record that failed to commit, used to put the
+        class name in the error message.
 
     The caller should pass either object or oid as a keyword argument,
     but not both of them.  If object is passed, it should be a
     persistent object with an _p_oid attribute.
     """
 
-    def __init__(self, message=None, object=None, oid=None, serials=None):
+    def __init__(self, message=None, object=None, oid=None, serials=None,
+                 data=None):
         if message is None:
             self.message = "database conflict error"
         else:
@@ -74,6 +78,14 @@
         if oid is not None:
             assert self.oid is None
             self.oid = oid
+
+        if data is not None:
+            # avoid circular import chain
+            from ZODB.serialize import SimpleObjectReader
+            self.class_name = SimpleObjectReader().getClassName(data)
+        else:
+            if message != "data read conflict error":
+                raise RuntimeError
 
         self.serials = serials
 


=== ZODB3/ZODB/serialize.py 1.1.2.3 => 1.1.2.4 ===
--- ZODB3/ZODB/serialize.py:1.1.2.3	Thu Oct 30 14:29:42 2003
+++ ZODB3/ZODB/serialize.py	Thu Oct 30 15:16:55 2003
@@ -179,8 +179,11 @@
 
     def getClassName(self, pickle):
         unpickler = self._get_unpickler(pickle)
-        cls, newargs = unpickler.load()
-        return cls.__name__
+        klass, newargs = unpickler.load()
+        if isinstance(klass, tuple):
+            return "%s.%s" % klass
+        else:
+            return klass.__name__
 
     def getGhost(self, pickle):
         unpickler = self._get_unpickler(pickle)
@@ -206,6 +209,24 @@
         state = unpickler.load()
         obj.__setstate__(state)
         return obj
+
+class ExternalReference(object):
+    pass
+
+class SimpleObjectReader(BaseObjectReader):
+    """Can be used to inspect a single object pickle.
+
+    It returns an ExternalReference() object for other persistent
+    objects.  It can't instantiate the object.
+    """
+
+    ext_ref = ExternalReference()
+
+    def _persistent_load(self, oid):
+        return self.ext_ref
+
+    def _get_class(self, module, name):
+        return None
 
 class ConnectionObjectReader(BaseObjectReader):
 




More information about the Zodb-checkins mailing list