Index: ERP5/Document/BusinessTemplate.py =================================================================== --- ERP5/Document/BusinessTemplate.py (copie de travail) +++ ERP5/Document/BusinessTemplate.py (copie de travail) @@ -453,7 +453,8 @@ attr_list = [ '_dav_writelocks', '_filepath', '_owner', 'uid', 'workflow_history', '__ac_local_roles__' ] attr_list += { - 'Script (Python)': ('_lazy_compilation', 'Python_magic'), + 'Script (Python)': ('_code', '_lazy_compilation', 'Python_magic', + 'func_defaults', 'func_code'), 'Z SQL Method': ('template',), }.get(meta_type, ()) @@ -464,8 +465,6 @@ if meta_type == 'ERP5 PDF Form': if not obj.getProperty('business_template_include_content', 1): obj.deletePdfContent() - elif meta_type == 'Script (Python)': - obj._code = None return obj class ObjectTemplateItem(BaseTemplateItem): @@ -774,8 +773,7 @@ # install object obj = self._objects[path] if getattr(obj, 'meta_type', None) == 'Script (Python)': - if getattr(obj, '_code') is None: - obj._compile() + obj._compile() if getattr(aq_base(obj), 'groups', None) is not None: # we must keep original order groups # because they change when we add subobjects @@ -1348,8 +1346,7 @@ container.manage_delObjects([object_id]) obj = self._objects[path] if getattr(obj, 'meta_type', None) == 'Script (Python)': - if getattr(obj, '_code') is None: - obj._compile() + obj._compile() obj = obj._getCopy(container) container._setObject(object_id, obj) obj = container._getOb(object_id) Index: ERP5Type/tests/ERP5TypeTestCase.py =================================================================== --- ERP5Type/tests/ERP5TypeTestCase.py (révision 23136) +++ ERP5Type/tests/ERP5TypeTestCase.py (copie de travail) @@ -950,6 +950,16 @@ ''' self._close() +class lazy_func_code(object): + def __init__(self, parent): + self.parent = parent + def __getstate__(self): + pass + def __getattr__(self, attr): + self.parent.func_code = None + self.parent._old_compile() + return getattr(self.parent.func_code, attr) + def optimize(): '''Significantly reduces portal creation time.''' def __init__(self, text): @@ -960,21 +970,22 @@ # Delay the compilations of Python Scripts until they are really executed. from Products.PythonScripts.PythonScript import PythonScript - PythonScript_compile = PythonScript._compile + PythonScript._old_compile = PythonScript._compile def _compile(self): - self._lazy_compilation = 1 + self.func_code = lazy_func_code(self) PythonScript._compile = _compile PythonScript_exec = PythonScript._exec def _exec(self, *args): - if getattr(self, '_lazy_compilation', 0): - self._lazy_compilation = 0 - PythonScript_compile(self) + if getattr(self, 'func_code', None).__class__ is lazy_func_code: + self.func_code = None + self._old_compile() return PythonScript_exec(self, *args) PythonScript._exec = _exec from Acquisition import aq_parent def _makeFunction(self, dummy=0): # CMFCore.FSPythonScript uses dummy arg. self.ZCacheable_invalidate() - PythonScript_compile(self) + self.func_code = None + self._old_compile() if not (aq_parent(self) is None or hasattr(self, '_filepath')): # It needs a _filepath, and has an acquisition wrapper. self._filepath = self.get_filepath()