Commit ddd1218d authored by Jeremy Hylton's avatar Jeremy Hylton

Frontport bug fixes in ConflictResolution to the trunk.

The main idea in the bug fix is to recover more gracefully when
something goes wrong trying to load classes for conflict resolution.

XXX This accidentally got checked in on the Zope 2.5 branch first.
parent 65c8a51d
...@@ -15,6 +15,7 @@ from cStringIO import StringIO ...@@ -15,6 +15,7 @@ from cStringIO import StringIO
from cPickle import Unpickler, Pickler from cPickle import Unpickler, Pickler
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
import zLOG
bad_classes = {} bad_classes = {}
...@@ -70,20 +71,29 @@ def persistent_id(object): ...@@ -70,20 +71,29 @@ def persistent_id(object):
return None return None
return object.data return object.data
def load_class(class_tuple):
try:
klass = _classFactory(class_tuple[0], class_tuple[1])
except (ImportError, AttributeError):
zLOG.LOG("Conflict Resolution", zLOG.BLATHER,
"Unable to load class", error=sys.exc_info())
bad_class[class_tuple] = 1
return None
return klass
def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle, def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle,
committedData=''): committedData=''):
#class_tuple, old, committed, newstate = ('',''), 0, 0, 0 # class_tuple, old, committed, newstate = ('',''), 0, 0, 0
try: try:
prfactory = PersistentReferenceFactory()
file = StringIO(newpickle) file = StringIO(newpickle)
unpickler = Unpickler(file) unpickler = Unpickler(file)
prfactory = PersistentReferenceFactory()
unpickler.persistent_load = prfactory.persistent_load unpickler.persistent_load = prfactory.persistent_load
class_tuple = unpickler.load()[0] class_tuple = unpickler.load()[0]
if bad_class(class_tuple): if bad_class(class_tuple):
return 0 return 0
newstate = unpickler.load() newstate = unpickler.load()
klass = _classFactory(class_tuple[0], class_tuple[1]) klass = load_class(class_tuple)
inst = klass.__basicnew__() inst = klass.__basicnew__()
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment