summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2014-07-14 17:53:23 +0300
committerAnssi Kääriäinen <akaariai@gmail.com>2014-08-12 14:58:10 +0300
commitf7dba61881ff5c26ad1c9a6dff71a8dc4ebede5a (patch)
treed5fca27a8844f00fa7c133c2a88d0428847460b3 /django
parent5b0375ec3e7473fcc29c21003fef80c0d0be183f (diff)
Avoided creation of deferred model from another deferred model
Also never create deferred model when no attrs are deferred.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/query_utils.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py
index be37bc8632..a8699f6334 100644
--- a/django/db/models/query_utils.py
+++ b/django/db/models/query_utils.py
@@ -186,6 +186,14 @@ def deferred_class_factory(model, attrs):
being replaced with DeferredAttribute objects. The "pk_value" ties the
deferred attributes to a particular instance of the model.
"""
+ if not attrs:
+ return model
+ # 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
# 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