mirror of
https://github.com/django/django.git
synced 2025-02-28 11:34:28 +00:00
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.
This commit is contained in:
parent
80d74097b4
commit
966de84973
@ -109,39 +109,15 @@ class Apps(object):
|
||||
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
|
||||
self.clear_cache()
|
||||
self._models_loaded = True
|
||||
|
||||
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
|
||||
|
||||
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):
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user