summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2015-10-19 14:17:55 -0400
committerSimon Charette <charette.s@gmail.com>2015-10-19 20:13:16 -0400
commit522b0bc91f6eddfcc8b8cc0f3d3566983f5bdfc2 (patch)
treecb6f02d1228f90c00ce36369d793bc5e16407b8f /django/db
parent094a60847a3e480fe694ce6c9f33832168987e90 (diff)
[1.9.x] Fixed #25563 -- Cached deferred models in their proxied model's _meta.apps.
Thanks to Andriy Sokolovskiy for the report and Tim Graham for the review. Backport of 3db3ab71e97d34260057a6f51d4b2f72da30dc8d from master
Diffstat (limited to 'django/db')
-rw-r--r--django/db/models/query_utils.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py
index efc995b35f..b25b408230 100644
--- a/django/db/models/query_utils.py
+++ b/django/db/models/query_utils.py
@@ -10,7 +10,6 @@ from __future__ import unicode_literals
import inspect
from collections import namedtuple
-from django.apps import apps
from django.core.exceptions import FieldDoesNotExist
from django.db.backends import utils
from django.db.models.constants import LOOKUP_SEP
@@ -272,12 +271,13 @@ def deferred_class_factory(model, attrs):
"""
if not attrs:
return model
+ opts = model._meta
# Never create deferred models based on deferred model
if model._deferred:
# Deferred models are proxies for the non-deferred model. We never
# create chains of defers => proxy_for_model is the non-deferred
# model.
- model = model._meta.proxy_for_model
+ model = opts.proxy_for_model
# The app registry wants a unique name for each model, otherwise the new
# class won't be created (we get an exception). Therefore, we generate
# the name using the passed in attrs. It's OK to reuse an existing class
@@ -286,13 +286,14 @@ def deferred_class_factory(model, attrs):
name = utils.truncate_name(name, 80, 32)
try:
- return apps.get_model(model._meta.app_label, name)
+ return opts.apps.get_model(model._meta.app_label, name)
except LookupError:
class Meta:
proxy = True
- app_label = model._meta.app_label
+ apps = opts.apps
+ app_label = opts.app_label
overrides = {attr: DeferredAttribute(attr, model) for attr in attrs}
overrides["Meta"] = Meta