Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed postponing in Apps.populate_models.

To the best of my understanding, since populate_models() is now called
as soon as Django starts, it cannot be called while a models module is
being imported, and that removes the need for postponing.

(If hell breaks loose we'll revert this commit.)

Refs #21681.
  • Loading branch information...
commit 966de8497373dc47756105516b4b839734ed316e 1 parent 80d7409
@aaugustin aaugustin authored
Showing with 6 additions and 30 deletions.
  1. +6 −30 django/apps/registry.py
View
36 django/apps/registry.py
@@ -109,39 +109,15 @@ def populate_models(self):
raise RuntimeError(
"populate_models() must run after populate_apps()")
- # Models modules are likely to import other models modules, for
- # example to reference related objects. As a consequence:
- # - we deal with import loops by postponing affected modules.
- # - we provide reentrancy by making import_models() idempotent.
-
- outermost = not hasattr(self, '_postponed')
- if outermost:
- self._postponed = []
-
for app_config in self.app_configs.values():
+ all_models = self.all_models[app_config.label]
+ app_config.import_models(all_models)
- if app_config.models is not None:
- continue
-
- try:
- all_models = self.all_models[app_config.label]
- app_config.import_models(all_models)
- except ImportError:
- self._postponed.append(app_config)
-
- if outermost:
- try:
- for app_config in self._postponed:
- all_models = self.all_models[app_config.label]
- app_config.import_models(all_models)
- finally:
- del self._postponed
-
- self.clear_cache()
- self._models_loaded = True
+ self.clear_cache()
+ self._models_loaded = True
- for app_config in self.get_app_configs():
- app_config.setup()
+ for app_config in self.get_app_configs():
+ app_config.setup()
def check_ready(self):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.