From 966de8497373dc47756105516b4b839734ed316e Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Mon, 30 Dec 2013 23:01:00 +0100 Subject: [PATCH] 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. --- django/apps/registry.py | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/django/apps/registry.py b/django/apps/registry.py index 0e39068e1f..9152e80593 100644 --- a/django/apps/registry.py +++ b/django/apps/registry.py @@ -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): """