Commit c2ce3ba0 authored by Arnaud Fontaine's avatar Arnaud Fontaine

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

parent cb631f83
No related merge requests found
...@@ -407,6 +407,32 @@ class ComponentDynamicPackage(ModuleType): ...@@ -407,6 +407,32 @@ class ComponentDynamicPackage(ModuleType):
with aq_method_lock: with aq_method_lock:
return self.__load_module(fullname) 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): def reset(self, sub_package=None):
""" """
Reset the content of the current package and its version package as well Reset the content of the current package and its version package as well
......
...@@ -195,22 +195,15 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -195,22 +195,15 @@ def generatePortalTypeClass(site, portal_type_name):
if not (type_class_namespace.startswith('Products.ERP5Type') or if not (type_class_namespace.startswith('Products.ERP5Type') or
portal_type_name in core_portal_type_class_dict): portal_type_name in core_portal_type_class_dict):
import erp5.component.document import erp5.component.document
module_fullname = 'erp5.component.document.' + type_class module = erp5.component.document.find_load_module(type_class)
module_loader = erp5.component.document.find_module(module_fullname) if module is not None:
if module_loader is not None:
try: try:
module = module_loader.load_module(module_fullname) klass = getattr(module, type_class)
except ImportError, e: except AttributeError:
LOG("ERP5Type.dynamic", WARNING, LOG("ERP5Type.dynamic", WARNING,
"Could not load Component module '%s': %s" % (module_fullname, e)) "Could not get class '%s' in Component module '%s'" % \
else: (type_class,
try: module_fullname))
klass = getattr(module, type_class)
except AttributeError:
LOG("ERP5Type.dynamic", WARNING,
"Could not get class '%s' in Component module '%s'" % \
(type_class,
module_fullname))
if klass is None: if klass is None:
type_class_path = document_class_registry.get(type_class) type_class_path = document_class_registry.get(type_class)
......
...@@ -81,11 +81,11 @@ if 1: ...@@ -81,11 +81,11 @@ if 1:
- fix magic "self" argument when positional arguments get their values - fix magic "self" argument when positional arguments get their values
from kw. from kw.
""" """
try: import erp5.component.extension
component_module = __import__('erp5.component.extension.' + self._module, component_module = erp5.component.extension.find_load_module(self._module)
fromlist=['erp5.component.extension'], if component_module is not None:
level=0) f = getattr(component_module, self._function)
except ImportError: else:
import Globals # for data import Globals # for data
filePath = self.filepath() filePath = self.filepath()
...@@ -103,8 +103,6 @@ if 1: ...@@ -103,8 +103,6 @@ if 1:
self.reloadIfChanged() self.reloadIfChanged()
f = None f = None
else:
f = getattr(component_module, self._function)
_v_f = getattr(self, '_v_f', None) _v_f = getattr(self, '_v_f', None)
if not _v_f or (f and f is not _v_f): 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