#33107: ImportError: partially initialized module '...' has no attribute '...'
---------------------------------+------------------------------------
Reporter: Collin Anderson | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Comment (by Mariusz Felisiak):
The easiest (but hacky) way to fix it is to check Python's internals and
reload the module again:
{{{
diff --git a/django/utils/module_loading.py
b/django/utils/module_loading.py
index 1df82b1c32..39cb784f72 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 it not fully initialize.
+ 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)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33107#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/072.a8a339e858246772fc59cc8ea0414df4%40djangoproject.com.