Commit 30edcbd4 authored by Julien Muchembled's avatar Julien Muchembled

Do not fail completely if portal type class can't be loaded

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39707 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d9243173
# -*- coding: utf-8 -*-
import sys
from Products.ERP5Type.Base import Base as ERP5Base from Products.ERP5Type.Base import Base as ERP5Base
from ExtensionClass import Base as ExtensionBase from ExtensionClass import Base as ExtensionBase
from ZODB.broken import Broken, PersistentBroken
from zLOG import LOG, ERROR, BLATHER from zLOG import LOG, ERROR, BLATHER
# PersistentBroken can't be reused directly
# because its « layout differs from 'GhostPortalType' »
ERP5BaseBroken = type('ERP5BaseBroken', (Broken, ERP5Base), dict(x
for x in PersistentBroken.__dict__.iteritems()
if x[0] not in ('__dict__', '__module__', '__weakref__')))
def generateLazyPortalTypeClass(portal_type_name, def generateLazyPortalTypeClass(portal_type_name,
portal_type_class_loader): portal_type_class_loader):
def load(self, attr): def load(self, attr):
klass = None
# self might be a subclass of a portal type class # self might be a subclass of a portal type class
# we need to find the right parent class to change # we need to find the right parent class to change
for candidate_klass in self.__class__.__mro__: for klass in self.__class__.__mro__:
# XXX hardcoded, this doesnt look too good # XXX hardcoded, this doesnt look too good
if candidate_klass.__module__ == "erp5.portal_type": if klass.__module__ == "erp5.portal_type":
klass = candidate_klass
break break
if klass is None: else:
raise AttributeError("Could not find a portal type class in class hierarchy") raise AttributeError("Could not find a portal type class in class hierarchy")
portal_type = klass.__name__ portal_type = klass.__name__
...@@ -22,11 +29,10 @@ def generateLazyPortalTypeClass(portal_type_name, ...@@ -22,11 +29,10 @@ def generateLazyPortalTypeClass(portal_type_name,
baseclasses, attributes = portal_type_class_loader(portal_type) baseclasses, attributes = portal_type_class_loader(portal_type)
except AttributeError: except AttributeError:
LOG("ERP5Type.Dynamic", ERROR, LOG("ERP5Type.Dynamic", ERROR,
"Could not access Portal Type Object for type %s" "Could not access Portal Type Object for type %r"
% portal_type_name) % portal_type, error=sys.exc_info())
import traceback; traceback.print_exc() baseclasses = (ERP5BaseBroken, )
raise AttributeError("Could not access Portal Type Object for type %s" attributes = {}
% portal_type_name)
# save the old bases to be able to restore a ghost state later # save the old bases to be able to restore a ghost state later
klass.__ghostbase__ = klass.__bases__ klass.__ghostbase__ = klass.__bases__
......
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