Commit c2ce3ba0 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Log error *and* traceback for both Extension and Document Components.

parent cb631f83
......@@ -407,6 +407,32 @@ class ComponentDynamicPackage(ModuleType):
with aq_method_lock:
return self.__load_module(fullname)
def find_load_module(self, name):
"""
Find and load a Component module.
When FS fallback is required (mainly for Document and Extension), this
should be used over a plain import to distinguish a document not available
as ZODB Component to an error in a Component, especially because in the
latter case only ImportError can be raised (PEP-302).
For example: if a Component tries to import another Component module but
the latter has been disabled and there is a fallback on the filesystem, a
plain import would hide the real error, instead log it...
"""
fullname = self._namespace + '.' + name
loader = self.find_module(fullname)
if loader is not None:
try:
return loader.load_module(fullname)
except ImportError, e:
import traceback
LOG("ERP5Type.dynamic", WARNING,
"Could not load Component module '%s'\n%s" % (fullname,
traceback.format_exc()))
return None
def reset(self, sub_package=None):
"""
Reset the content of the current package and its version package as well
......
......@@ -195,22 +195,15 @@ def generatePortalTypeClass(site, portal_type_name):
if not (type_class_namespace.startswith('Products.ERP5Type') or
portal_type_name in core_portal_type_class_dict):
import erp5.component.document
module_fullname = 'erp5.component.document.' + type_class
module_loader = erp5.component.document.find_module(module_fullname)
if module_loader is not None:
module = erp5.component.document.find_load_module(type_class)
if module is not None:
try:
module = module_loader.load_module(module_fullname)
except ImportError, e:
klass = getattr(module, type_class)
except AttributeError:
LOG("ERP5Type.dynamic", WARNING,
"Could not load Component module '%s': %s" % (module_fullname, e))
else:
try:
klass = getattr(module, type_class)
except AttributeError:
LOG("ERP5Type.dynamic", WARNING,
"Could not get class '%s' in Component module '%s'" % \
(type_class,
module_fullname))
"Could not get class '%s' in Component module '%s'" % \
(type_class,
module_fullname))
if klass is None:
type_class_path = document_class_registry.get(type_class)
......
......@@ -81,11 +81,11 @@ if 1:
- fix magic "self" argument when positional arguments get their values
from kw.
"""
try:
component_module = __import__('erp5.component.extension.' + self._module,
fromlist=['erp5.component.extension'],
level=0)
except ImportError:
import erp5.component.extension
component_module = erp5.component.extension.find_load_module(self._module)
if component_module is not None:
f = getattr(component_module, self._function)
else:
import Globals # for data
filePath = self.filepath()
......@@ -103,8 +103,6 @@ if 1:
self.reloadIfChanged()
f = None
else:
f = getattr(component_module, self._function)
_v_f = getattr(self, '_v_f', None)
if not _v_f or (f and f is not _v_f):
......
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