From d44de9b933fb7d987d814034769a1ba2eda6545c Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 14 Dec 2013 09:50:28 +0100 Subject: [PATCH] Removed the _-prefix for populate(). Several parts of Django call get_apps() with a comment along this lines of "this has the side effect of calling _populate()". I fail to see how this is better than just calling populate()! --- django/apps/cache.py | 14 +++++++------- django/contrib/admin/validation.py | 6 +++--- django/core/serializers/base.py | 7 +++---- django/core/serializers/python.py | 3 ++- django/db/models/loading.py | 2 +- tests/runtests.py | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/django/apps/cache.py b/django/apps/cache.py index b125d6b4c6..9d762a58ec 100644 --- a/django/apps/cache.py +++ b/django/apps/cache.py @@ -60,11 +60,11 @@ class BaseAppCache(object): def __init__(self): self.__dict__ = _initialize() - # This stops _populate loading from INSTALLED_APPS and ignores the + # This stops populate loading from INSTALLED_APPS and ignores the # only_installed arguments to get_model[s] self.loads_installed = False - def _populate(self): + def populate(self): """ Fill in all the cache information. This method is threadsafe, in the sense that every caller will see the same state upon return, and if the @@ -161,7 +161,7 @@ class BaseAppCache(object): If only_installed is True (default), only applications explicitly listed in INSTALLED_APPS are considered. """ - self._populate() + self.populate() for app_config in self.app_configs.values(): if only_installed and not app_config.installed: continue @@ -181,7 +181,7 @@ class BaseAppCache(object): If only_installed is True (default), only applications explicitly listed in INSTALLED_APPS are considered. """ - self._populate() + self.populate() app_config = self.app_configs.get(app_label) if app_config is None or (only_installed and not app_config.installed): raise LookupError("No app with label %r." % app_label) @@ -246,7 +246,7 @@ class BaseAppCache(object): return model_list except KeyError: pass - self._populate() + self.populate() if app_mod: app_label = self._label_for(app_mod) try: @@ -289,7 +289,7 @@ class BaseAppCache(object): if not self.loads_installed: only_installed = False if seed_cache: - self._populate() + self.populate() if only_installed: app_config = self.app_configs.get(app_label) if app_config is not None and not app_config.installed: @@ -371,7 +371,7 @@ class BaseAppCache(object): "[a.path for a in get_app_configs()] supersedes get_app_paths().", PendingDeprecationWarning, stacklevel=2) - self._populate() + self.populate() app_paths = [] for app in self.get_apps(): diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index c8bd4af120..79fa9c672c 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -16,9 +16,9 @@ __all__ = ['BaseValidator', 'InlineValidator'] class BaseValidator(object): def __init__(self): - # Before we can introspect models, they need to be fully loaded so that - # inter-relations are set up correctly. We force that here. - app_cache.get_apps() + # Before we can introspect models, they need the app cache to be fully + # loaded so that inter-relations are set up correctly. + app_cache.populate() def validate(self, cls, model): for m in dir(self): diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py index e575c1d1c2..98fbb081c5 100644 --- a/django/core/serializers/base.py +++ b/django/core/serializers/base.py @@ -137,10 +137,9 @@ class Deserializer(six.Iterator): self.stream = six.StringIO(stream_or_string) else: self.stream = stream_or_string - # hack to make sure that the models have all been loaded before - # deserialization starts (otherwise subclass calls to get_model() - # and friends might fail...) - app_cache.get_apps() + # Make sure the app cache is loaded before deserialization starts + # (otherwise subclass calls to get_model() and friends might fail...) + app_cache.populate() def __iter__(self): return self diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index 07f857a198..47edc80217 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -88,7 +88,8 @@ def Deserializer(object_list, **options): db = options.pop('using', DEFAULT_DB_ALIAS) ignore = options.pop('ignorenonexistent', False) - app_cache.get_apps() + app_cache.populate() + for d in object_list: # Look up the model and starting build a dict of data for it. Model = _get_model(d["model"]) diff --git a/django/db/models/loading.py b/django/db/models/loading.py index f814f949e4..ad267d8462 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -30,6 +30,6 @@ def get_app_errors(): try: return app_cache.app_errors except AttributeError: - app_cache._populate() + app_cache.populate() app_cache.app_errors = {} return app_cache.app_errors diff --git a/tests/runtests.py b/tests/runtests.py index 9ef81f8877..c294664c31 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -128,7 +128,7 @@ def setup(verbosity, test_labels): # Load all the ALWAYS_INSTALLED_APPS. with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'django.contrib.comments is deprecated and will be removed before Django 1.8.', DeprecationWarning) - app_cache.get_apps() + app_cache.populate() # Load all the test model apps. test_modules = get_test_modules()