Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix #17876: Corrected an exception (regression) raised where select_r…

…ealted and only is used on a proxy model. Thanks milosu and charettes.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17692 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9d98b9eb4bee1c9d69694f37dc618c36ecfecb8d 1 parent db512b4
Karen Tracey authored March 12, 2012
2  django/db/models/query.py
@@ -1266,7 +1266,7 @@ def get_klass_info(klass, max_depth=0, cur_depth=0, requested=None,
1266 1266
         return None
1267 1267
 
1268 1268
     if only_load:
1269  
-        load_fields = only_load.get(klass)
  1269
+        load_fields = only_load.get(klass) or set()
1270 1270
         # When we create the object, we will also be creating populating
1271 1271
         # all the parent classes, so traverse the parent classes looking
1272 1272
         # for fields that must be included on load.
4  tests/modeltests/defer/models.py
@@ -22,3 +22,7 @@ class Child(Primary):
22 22
 
23 23
 class BigChild(Primary):
24 24
     other = models.CharField(max_length=50)
  25
+
  26
+class ChildProxy(Child):
  27
+    class Meta:
  28
+        proxy=True
6  tests/modeltests/defer/tests.py
@@ -3,7 +3,7 @@
3 3
 from django.db.models.query_utils import DeferredAttribute
4 4
 from django.test import TestCase
5 5
 
6  
-from .models import Secondary, Primary, Child, BigChild
  6
+from .models import Secondary, Primary, Child, BigChild, ChildProxy
7 7
 
8 8
 
9 9
 class DeferTests(TestCase):
@@ -145,3 +145,7 @@ def test_defer(self):
145 145
         obj.name = "bb"
146 146
         obj.save()
147 147
 
  148
+    def test_defer_proxy(self):
  149
+        # using select related and only should not result in Exception
  150
+        for obj in ChildProxy.objects.all().select_related().only('id'):
  151
+            continue

0 notes on commit 9d98b9e

Please sign in to comment.
Something went wrong with that request. Please try again.