Fixed #24559 -- Made MigrationLoader.load_disk() catch more specific ModuleNotFoundError.
Avoids inspecting the exception message, which is not considered a stable API and can change across Python versions. ModuleNotFoundError was introduced in Python 3.6. It is a subclass of ImportError that is raised when the imported module does not exist. It is not raised for other errors that can occur during an import. This exception instance has the property "name" which holds the name of module that failed to import.
This commit is contained in:
parent
141ab6bc6d
commit
661e39c8d5
|
@ -79,11 +79,11 @@ class MigrationLoader:
|
||||||
was_loaded = module_name in sys.modules
|
was_loaded = module_name in sys.modules
|
||||||
try:
|
try:
|
||||||
module = import_module(module_name)
|
module = import_module(module_name)
|
||||||
except ImportError as e:
|
except ModuleNotFoundError as e:
|
||||||
# I hate doing this, but I don't want to squash other import errors.
|
if (
|
||||||
# Might be better to try a directory check directly.
|
(explicit and self.ignore_no_migrations) or
|
||||||
if ((explicit and self.ignore_no_migrations) or (
|
(not explicit and MIGRATIONS_MODULE_NAME in e.name.split('.'))
|
||||||
not explicit and "No module named" in str(e) and MIGRATIONS_MODULE_NAME in str(e))):
|
):
|
||||||
self.unmigrated_apps.add(app_config.label)
|
self.unmigrated_apps.add(app_config.label)
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Reference in New Issue