Added an _-prefix to pending lookups because it's transient.

This commit is contained in:
Aymeric Augustin 2013-12-18 16:49:42 +01:00
parent 86804ab063
commit 439b364e1e
2 changed files with 5 additions and 5 deletions

View File

@ -43,9 +43,6 @@ class AppCache(object):
# Mapping of labels to AppConfig instances for installed apps. # Mapping of labels to AppConfig instances for installed apps.
self.app_configs = OrderedDict() self.app_configs = OrderedDict()
# Pending lookups for lazy relations
self.pending_lookups = {}
# Set of app names. Allows restricting the set of installed apps. # Set of app names. Allows restricting the set of installed apps.
# Used by TransactionTestCase.available_apps for performance reasons. # Used by TransactionTestCase.available_apps for performance reasons.
self.available_apps = None self.available_apps = None
@ -54,6 +51,9 @@ class AppCache(object):
self._apps_loaded = not self.master self._apps_loaded = not self.master
self._models_loaded = not self.master self._models_loaded = not self.master
# Pending lookups for lazy relations.
self._pending_lookups = {}
# Cache for get_models. # Cache for get_models.
self._get_models_cache = {} self._get_models_cache = {}

View File

@ -74,7 +74,7 @@ def add_lazy_relation(cls, field, relation, operation):
else: else:
key = (app_label, model_name) key = (app_label, model_name)
value = (cls, field, operation) value = (cls, field, operation)
cls._meta.app_cache.pending_lookups.setdefault(key, []).append(value) cls._meta.app_cache._pending_lookups.setdefault(key, []).append(value)
def do_pending_lookups(sender, **kwargs): def do_pending_lookups(sender, **kwargs):
@ -82,7 +82,7 @@ def do_pending_lookups(sender, **kwargs):
Handle any pending relations to the sending model. Sent from class_prepared. Handle any pending relations to the sending model. Sent from class_prepared.
""" """
key = (sender._meta.app_label, sender.__name__) key = (sender._meta.app_label, sender.__name__)
for cls, field, operation in sender._meta.app_cache.pending_lookups.pop(key, []): for cls, field, operation in sender._meta.app_cache._pending_lookups.pop(key, []):
operation(field, sender, cls) operation(field, sender, cls)
signals.class_prepared.connect(do_pending_lookups) signals.class_prepared.connect(do_pending_lookups)