Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Fixed #14698 -- Ensure that module_has_sumodule doesn't mista…

…ke a cache miss for an existent package. Thanks to Łukasz Rekucki for the report and patch, and to shields for the test case.

Backport of r15362 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15364 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7e83c3b91f46458c6b2243b21ac144499bec47cf 1 parent a289eba
@freakboy3742 freakboy3742 authored
View
7 django/utils/module_loading.py
@@ -6,8 +6,11 @@
def module_has_submodule(package, module_name):
"""See if 'module' is in 'package'."""
name = ".".join([package.__name__, module_name])
- if name in sys.modules:
- return True
+ try:
+ # None indicates a cached miss; see mark_miss() in Python/import.c.
+ return sys.modules[name] is not None
+ except KeyError:
+ pass
for finder in sys.meta_path:
if finder.find_module(name):
return True
View
4 tests/regressiontests/utils/module_loading.py
@@ -24,6 +24,10 @@ def test_loader(self):
self.assertFalse(module_has_submodule(test_module, 'no_such_module'))
self.assertRaises(ImportError, import_module, 'regressiontests.utils.test_module.no_such_module')
+ # Don't be confused by caching of import misses
+ import types # causes attempted import of regressiontests.utils.types
+ self.assertFalse(module_has_submodule(sys.modules['regressiontests.utils'], 'types'))
+
class EggLoader(unittest.TestCase):
def setUp(self):
self.old_path = sys.path[:]
Please sign in to comment.
Something went wrong with that request. Please try again.