Commit 93b3d86b authored by Nicolas Dumazet's avatar Nicolas Dumazet

make PersistentMigrationMixin more bulletproof


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40944 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1ee55dd8
...@@ -902,24 +902,26 @@ class PersistentMigrationMixin(object): ...@@ -902,24 +902,26 @@ class PersistentMigrationMixin(object):
_no_migration = 0 _no_migration = 0
def __setstate__(self, value): def __setstate__(self, value):
if PersistentMigrationMixin._no_migration: klass = self.__class__
if PersistentMigrationMixin._no_migration \
or klass.__module__ in ('erp5.portal_type', 'erp5.temp_portal_type'):
super(PersistentMigrationMixin, self).__setstate__(value) super(PersistentMigrationMixin, self).__setstate__(value)
return return
portal_type = value.get('portal_type') portal_type = value.get('portal_type')
if portal_type is None: if portal_type is None:
portal_type = getattr(self.__class__, 'portal_type', None) portal_type = getattr(klass, 'portal_type', None)
if portal_type is None: if portal_type is None:
LOG('ERP5Type', PROBLEM, LOG('ERP5Type', PROBLEM,
"no portal type was found for %s (class %s)" \ "no portal type was found for %s (class %s)" \
% (self, self.__class__)) % (self, klass))
super(PersistentMigrationMixin, self).__setstate__(value) super(PersistentMigrationMixin, self).__setstate__(value)
else: else:
# proceed with migration # proceed with migration
import erp5.portal_type import erp5.portal_type
klass = getattr(erp5.portal_type, portal_type) newklass = getattr(erp5.portal_type, portal_type)
assert self.__class__ != klass assert self.__class__ != newklass
self.__class__ = klass self.__class__ = newklass
self.__setstate__(value) self.__setstate__(value)
LOG('ERP5Type', TRACE, "Migration for object %s" % self) LOG('ERP5Type', TRACE, "Migration for object %s" % self)
......
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