summaryrefslogtreecommitdiff
path: root/django
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:11:32 -0400
commit3db3ab71e97d34260057a6f51d4b2f72da30dc8d (patch)
tree9b249d9277badfa4192056dea55395a3f5c782b3 /django
parentaff4b75c34d62ec932414b5099016007fff17317 (diff)
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.
Diffstat (limited to 'django')
-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 d9040d0843..8e303e8f8a 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