diff --git a/django/core/apps/cache.py b/django/core/apps/cache.py index e9a4215440..74488325a8 100644 --- a/django/core/apps/cache.py +++ b/django/core/apps/cache.py @@ -43,9 +43,6 @@ class AppCache(object): # Mapping of labels to AppConfig instances for installed apps. self.app_configs = OrderedDict() - # Pending lookups for lazy relations - self.pending_lookups = {} - # Set of app names. Allows restricting the set of installed apps. # Used by TransactionTestCase.available_apps for performance reasons. self.available_apps = None @@ -54,6 +51,9 @@ class AppCache(object): self._apps_loaded = not self.master self._models_loaded = not self.master + # Pending lookups for lazy relations. + self._pending_lookups = {} + # Cache for get_models. self._get_models_cache = {} diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 1b141af099..cf35504afe 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -74,7 +74,7 @@ def add_lazy_relation(cls, field, relation, operation): else: key = (app_label, model_name) 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): @@ -82,7 +82,7 @@ def do_pending_lookups(sender, **kwargs): Handle any pending relations to the sending model. Sent from class_prepared. """ 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) signals.class_prepared.connect(do_pending_lookups)