summaryrefslogtreecommitdiff
path: root/django/utils/module_loading.py
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2014-10-31 10:22:15 +0100
committerTim Graham <timograham@gmail.com>2014-10-31 08:01:47 -0400
commit98da408964b229ee0b35bb8c4500820e3606aeab (patch)
tree2d5208b605524f0a565318806f708449f096e922 /django/utils/module_loading.py
parentc0c1bb9e64d7e1cea50dc4818ffcf229b568578b (diff)
Fixed #23670 -- Prevented partial import state during module autodiscovery
Thanks kostko for the report.
Diffstat (limited to 'django/utils/module_loading.py')
-rw-r--r--django/utils/module_loading.py34
1 files changed, 17 insertions, 17 deletions
diff --git a/django/utils/module_loading.py b/django/utils/module_loading.py
index 826aed8c00..cd0c8bc5cc 100644
--- a/django/utils/module_loading.py
+++ b/django/utils/module_loading.py
@@ -64,26 +64,26 @@ def autodiscover_modules(*args, **kwargs):
register_to = kwargs.get('register_to')
for app_config in apps.get_app_configs():
- # Attempt to import the app's module.
- try:
- if register_to:
- before_import_registry = copy.copy(register_to._registry)
+ for module_to_search in args:
+ # Attempt to import the app's module.
+ try:
+ if register_to:
+ before_import_registry = copy.copy(register_to._registry)
- for module_to_search in args:
import_module('%s.%s' % (app_config.name, module_to_search))
- except:
- # Reset the model registry to the state before the last import as
- # this import will have to reoccur on the next request and this
- # could raise NotRegistered and AlreadyRegistered exceptions
- # (see #8245).
- if register_to:
- register_to._registry = before_import_registry
+ except:
+ # Reset the registry to the state before the last import
+ # as this import will have to reoccur on the next request and
+ # this could raise NotRegistered and AlreadyRegistered
+ # exceptions (see #8245).
+ if register_to:
+ register_to._registry = before_import_registry
- # Decide whether to bubble up this error. If the app just
- # doesn't have an admin module, we can ignore the error
- # attempting to import it, otherwise we want it to bubble up.
- if module_has_submodule(app_config.module, module_to_search):
- raise
+ # Decide whether to bubble up this error. If the app just
+ # doesn't have the module in question, we can ignore the error
+ # attempting to import it, otherwise we want it to bubble up.
+ if module_has_submodule(app_config.module, module_to_search):
+ raise
if sys.version_info[:2] >= (3, 3):