From f6bd00131e687aedf2719ad31e84b097562ca5f2 Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Fri, 9 Jun 2017 06:34:20 +1200 Subject: Fixed #28241 -- Allowed module_has_submodule()'s module_name arg to be a dotted path. --- django/utils/module_loading.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'django/utils/module_loading.py') diff --git a/django/utils/module_loading.py b/django/utils/module_loading.py index 5e5fa0e69e..413c6c2540 100644 --- a/django/utils/module_loading.py +++ b/django/utils/module_loading.py @@ -70,7 +70,14 @@ def module_has_submodule(package, module_name): return False full_module_name = package_name + '.' + module_name - return importlib_find(full_module_name, package_path) is not None + try: + return importlib_find(full_module_name, package_path) is not None + except (ImportError, AttributeError): + # When module_name is an invalid dotted path, Python raises ImportError + # (or ModuleNotFoundError in Python 3.6+). AttributeError may be raised + # if the penultimate part of the path is not a package. + # (http://bugs.python.org/issue30436) + return False def module_dir(module): -- cgit v1.3