diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-09-16 07:12:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-16 07:12:58 +0200 |
| commit | 6426c3077c8048bb3fa5bfcec6be80f73476b534 (patch) | |
| tree | 22300d00fe15f1e3db5ae0c3dec247fac663ed9f /django/utils/module_loading.py | |
| parent | ec212c66167759a2a40b13d5efc47d883816d4da (diff) | |
Fixed #33107 -- Fixed import_string() crash on not fully initialized modules.
Regression in ecf87ad513fd8af6e4a6093ed918723a7d88d5ca.
Thanks Collin Anderson for the report.
Diffstat (limited to 'django/utils/module_loading.py')
| -rw-r--r-- | django/utils/module_loading.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/django/utils/module_loading.py b/django/utils/module_loading.py index 1df82b1c32..d42b9a5f22 100644 --- a/django/utils/module_loading.py +++ b/django/utils/module_loading.py @@ -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) |
