Fixed #33107 -- Fixed import_string() crash on not fully initialized modules.

Regression in ecf87ad513.

Thanks Collin Anderson for the report.
This commit is contained in:
Mariusz Felisiak 2021-09-16 07:12:58 +02:00 committed by GitHub
parent ec212c6616
commit 6426c3077c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -7,7 +7,11 @@ from importlib.util import find_spec as importlib_find
def cached_import(module_path, class_name):
modules = sys.modules
if module_path not in modules:
if module_path not in modules or (
# Module is not fully initialized.
getattr(modules[module_path], '__spec__', None) is not None and
getattr(modules[module_path].__spec__, '_initializing', False) is True
):
import_module(module_path)
return getattr(modules[module_path], class_name)