mirror of
https://github.com/django/django.git
synced 2025-08-08 04:48:27 +00:00
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.
This commit is contained in:
parent
aff4b75c34
commit
3db3ab71e9
3 changed files with 30 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue