diff options
| author | Simon Charette <charette.s@gmail.com> | 2015-10-19 14:17:55 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2015-10-19 20:13:47 -0400 |
| commit | 71962629c09958f2f324de7bb2fc0067b1a1b7fc (patch) | |
| tree | 73c7412ad7eb124e516a84ef31b20282d8bef332 /django | |
| parent | 9ccb92ad0130c0fc5fec43d3b914b49df688ffa5 (diff) | |
[1.8.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')
| -rw-r--r-- | django/db/models/query_utils.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index 3f24ab8cf1..4eca2c98d8 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -9,7 +9,6 @@ from __future__ import unicode_literals 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 @@ -215,12 +214,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 @@ -229,13 +229,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 |
