Commit 223d4818 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Alias module was not added to sys.modules if the module it...

ZODB Components: Alias module was not added to sys.modules if the module it points to had already been loaded before.
parent 96851e6a
...@@ -254,6 +254,8 @@ class ComponentDynamicPackage(ModuleType): ...@@ -254,6 +254,8 @@ class ComponentDynamicPackage(ModuleType):
raise ImportError("%s: no version of Component %s in Site priority" % \ raise ImportError("%s: no version of Component %s in Site priority" % \
(fullname, name)) (fullname, name))
module_fullname_alias = self._namespace + '.' + name
# Check whether this module has already been loaded before for a # Check whether this module has already been loaded before for a
# specific version, if so, just add it to the upper level # specific version, if so, just add it to the upper level
try: try:
...@@ -262,10 +264,9 @@ class ComponentDynamicPackage(ModuleType): ...@@ -262,10 +264,9 @@ class ComponentDynamicPackage(ModuleType):
pass pass
else: else:
setattr(self, name, module) setattr(self, name, module)
sys.modules[module_fullname_alias] = module
return module return module
module_fullname_alias = self._namespace + '.' + name
component = getattr(site.portal_components, component_id) component = getattr(site.portal_components, component_id)
relative_url = component.getRelativeUrl() relative_url = component.getRelativeUrl()
......
...@@ -35,6 +35,7 @@ import shutil ...@@ -35,6 +35,7 @@ import shutil
import tempfile import tempfile
import unittest import unittest
import warnings import warnings
import sys
import transaction import transaction
from persistent import Persistent from persistent import Persistent
...@@ -1524,9 +1525,13 @@ class _TestZodbComponent(SecurityTestCase): ...@@ -1524,9 +1525,13 @@ class _TestZodbComponent(SecurityTestCase):
reset_portal_type_at_transaction_boundary=False) reset_portal_type_at_transaction_boundary=False)
def _importModule(self, module_name): def _importModule(self, module_name):
return __import__(self._getComponentFullModuleName(module_name), module_name = self._getComponentFullModuleName(module_name)
module = __import__(
module_name,
fromlist=[self._document_class._getDynamicModuleNamespace()], fromlist=[self._document_class._getDynamicModuleNamespace()],
level=0) level=0)
self.assertTrue(module_name in sys.modules)
return module
def testValidateInvalidateDelete(self): def testValidateInvalidateDelete(self):
""" """
...@@ -1997,6 +2002,10 @@ def bar(*args, **kwargs): ...@@ -1997,6 +2002,10 @@ def bar(*args, **kwargs):
self.assertHasAttribute(module, 'bar') self.assertHasAttribute(module, 'bar')
self.assertEqual(module.bar(), 'BarTestImportedVersionedComponentOnly') self.assertEqual(module.bar(), 'BarTestImportedVersionedComponentOnly')
# Now check that the alias module on the top-level package is properly
# created when importing it
self._importModule(imported_reference)
def testVersionPriority(self): def testVersionPriority(self):
""" """
Check whether Version priorities properly works by adding and removing Check whether Version priorities properly works by adding and removing
......
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