Commit 3a92d8b6 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: When executing code, module globals disappeared after a reset...

ZODB Components: When executing code, module globals disappeared after a reset performed in another thread.

This fixes failures in erp5_configurator* tests where BTs installed during the
tests trigger a reset and globals (such as DateTime global import) were reset to
parent 19b3a67d
......@@ -34,6 +34,7 @@ import sys
import imp
from Products.ERP5.ERP5Site import getSite
from Products.ERP5Type.Globals import get_request
from . import aq_method_lock
from types import ModuleType
from zLOG import LOG, BLATHER
......@@ -369,6 +370,23 @@ class ComponentDynamicPackage(ModuleType):
if module_fullname_alias:
setattr(self, name, module)
# When the reference counter of a module reaches 0, its globals are all
# reset to None. So, if a thread performs a reset while another one
# executes codes using globals (such as modules imported at module level),
# the latter one must keep a reference around to avoid reaching a
# reference count to 0. Thus, add it to Request object.
# OTOH, this means that ZODB Components module *must* be imported at the
# top level, otherwise a module being relied upon may have a different API
# after rset, thus it may fail...
request_obj = get_request()
module_cache_set = getattr(request_obj, '_module_cache_set', None)
if module_cache_set is None:
module_cache_set = set()
request_obj._module_cache_set = module_cache_set
return module
# load_module() can be called outside of import machinery, for example
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment