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,15 +195,8 @@ 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:
try:
module = module_loader.load_module(module_fullname)
except ImportError, e:
LOG("ERP5Type.dynamic", WARNING,
"Could not load Component module '%s': %s" % (module_fullname, e))
else:
module = erp5.component.document.find_load_module(type_class)
if module is not None:
try:
klass = getattr(module, type_class)
except AttributeError:
......
......@@ -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):
......
  • I want to revert because find_load_module is much slower that __import__ This is important for Extensions because this is done on every execution (to reload automatically). We should find a different to get the interesting information logged.

    Edited by Julien Muchembled
  • mentioned in commit b45914fa

    Toggle commit list
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