Skip to content

Commit

Permalink
Fixed #35402 -- Fixed crash when DatabaseFeatures.django_test_skips r…
Browse files Browse the repository at this point in the history
…eferences a class in another test module

Previously, if a submodule skipped test classes in an adjacent submodule (same
parent module), only the running submodule was imported and an error was thrown
because getattr would not find the submodule of the to-be-skipped class. Updated
cached_import in django/utils/module_loading.py to include a check for the skipped
submodule, and import it if it is not there.

Thanks to Tim Graham for reporting this bug
  • Loading branch information
jonmcfee03 committed Apr 26, 2024
1 parent a0b3a19 commit 3cb0d30
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion django/utils/module_loading.py
Expand Up @@ -14,7 +14,10 @@ def cached_import(module_path, class_name):
):
module = import_module(module_path)
if not hasattr(module, class_name):
import_module(f"{module_path}.{class_name}")
try:
import_module(f"{module_path}.{class_name}")
except ImportError:
pass
return getattr(module, class_name)


Expand Down

0 comments on commit 3cb0d30

Please sign in to comment.