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()!
This commit is contained in:
Aymeric Augustin 2013-12-14 09:50:28 +01:00
parent ebda5800ae
commit d44de9b933
6 changed files with 17 additions and 17 deletions

View File

@ -60,11 +60,11 @@ class BaseAppCache(object):
def __init__(self): def __init__(self):
self.__dict__ = _initialize() 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] # only_installed arguments to get_model[s]
self.loads_installed = False self.loads_installed = False
def _populate(self): def populate(self):
""" """
Fill in all the cache information. This method is threadsafe, in the 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 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 If only_installed is True (default), only applications explicitly
listed in INSTALLED_APPS are considered. listed in INSTALLED_APPS are considered.
""" """
self._populate() self.populate()
for app_config in self.app_configs.values(): for app_config in self.app_configs.values():
if only_installed and not app_config.installed: if only_installed and not app_config.installed:
continue continue
@ -181,7 +181,7 @@ class BaseAppCache(object):
If only_installed is True (default), only applications explicitly If only_installed is True (default), only applications explicitly
listed in INSTALLED_APPS are considered. listed in INSTALLED_APPS are considered.
""" """
self._populate() self.populate()
app_config = self.app_configs.get(app_label) app_config = self.app_configs.get(app_label)
if app_config is None or (only_installed and not app_config.installed): if app_config is None or (only_installed and not app_config.installed):
raise LookupError("No app with label %r." % app_label) raise LookupError("No app with label %r." % app_label)
@ -246,7 +246,7 @@ class BaseAppCache(object):
return model_list return model_list
except KeyError: except KeyError:
pass pass
self._populate() self.populate()
if app_mod: if app_mod:
app_label = self._label_for(app_mod) app_label = self._label_for(app_mod)
try: try:
@ -289,7 +289,7 @@ class BaseAppCache(object):
if not self.loads_installed: if not self.loads_installed:
only_installed = False only_installed = False
if seed_cache: if seed_cache:
self._populate() self.populate()
if only_installed: if only_installed:
app_config = self.app_configs.get(app_label) app_config = self.app_configs.get(app_label)
if app_config is not None and not app_config.installed: 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().", "[a.path for a in get_app_configs()] supersedes get_app_paths().",
PendingDeprecationWarning, stacklevel=2) PendingDeprecationWarning, stacklevel=2)
self._populate() self.populate()
app_paths = [] app_paths = []
for app in self.get_apps(): for app in self.get_apps():

View File

@ -16,9 +16,9 @@ __all__ = ['BaseValidator', 'InlineValidator']
class BaseValidator(object): class BaseValidator(object):
def __init__(self): def __init__(self):
# Before we can introspect models, they need to be fully loaded so that # Before we can introspect models, they need the app cache to be fully
# inter-relations are set up correctly. We force that here. # loaded so that inter-relations are set up correctly.
app_cache.get_apps() app_cache.populate()
def validate(self, cls, model): def validate(self, cls, model):
for m in dir(self): for m in dir(self):

View File

@ -137,10 +137,9 @@ class Deserializer(six.Iterator):
self.stream = six.StringIO(stream_or_string) self.stream = six.StringIO(stream_or_string)
else: else:
self.stream = stream_or_string self.stream = stream_or_string
# hack to make sure that the models have all been loaded before # Make sure the app cache is loaded before deserialization starts
# deserialization starts (otherwise subclass calls to get_model() # (otherwise subclass calls to get_model() and friends might fail...)
# and friends might fail...) app_cache.populate()
app_cache.get_apps()
def __iter__(self): def __iter__(self):
return self return self

View File

@ -88,7 +88,8 @@ def Deserializer(object_list, **options):
db = options.pop('using', DEFAULT_DB_ALIAS) db = options.pop('using', DEFAULT_DB_ALIAS)
ignore = options.pop('ignorenonexistent', False) ignore = options.pop('ignorenonexistent', False)
app_cache.get_apps() app_cache.populate()
for d in object_list: for d in object_list:
# Look up the model and starting build a dict of data for it. # Look up the model and starting build a dict of data for it.
Model = _get_model(d["model"]) Model = _get_model(d["model"])

View File

@ -30,6 +30,6 @@ def get_app_errors():
try: try:
return app_cache.app_errors return app_cache.app_errors
except AttributeError: except AttributeError:
app_cache._populate() app_cache.populate()
app_cache.app_errors = {} app_cache.app_errors = {}
return app_cache.app_errors return app_cache.app_errors

View File

@ -128,7 +128,7 @@ def setup(verbosity, test_labels):
# Load all the ALWAYS_INSTALLED_APPS. # Load all the ALWAYS_INSTALLED_APPS.
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.filterwarnings('ignore', 'django.contrib.comments is deprecated and will be removed before Django 1.8.', DeprecationWarning) 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. # Load all the test model apps.
test_modules = get_test_modules() test_modules = get_test_modules()