Commit 966de849 authored by Aymeric Augustin's avatar Aymeric Augustin
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.
parent 80d74097
Loading
Loading
Loading
Loading
+6 −30
Original line number Diff line number Diff line
@@ -109,33 +109,9 @@ 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():

                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