Browse files

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...
1 parent db512b4 commit 9d98b9eb4bee1c9d69694f37dc618c36ecfecb8d @kmtracey kmtracey committed Mar 12, 2012
Showing with 10 additions and 2 deletions.
  1. +1 −1 django/db/models/query.py
  2. +4 −0 tests/modeltests/defer/models.py
  3. +5 −1 tests/modeltests/defer/tests.py
View
2 django/db/models/query.py
@@ -1266,7 +1266,7 @@ def get_klass_info(klass, max_depth=0, cur_depth=0, requested=None,
return None
if only_load:
- load_fields = only_load.get(klass)
+ load_fields = only_load.get(klass) or set()
# When we create the object, we will also be creating populating
# all the parent classes, so traverse the parent classes looking
# for fields that must be included on load.
View
4 tests/modeltests/defer/models.py
@@ -22,3 +22,7 @@ class Child(Primary):
class BigChild(Primary):
other = models.CharField(max_length=50)
+
+class ChildProxy(Child):
+ class Meta:
+ proxy=True
View
6 tests/modeltests/defer/tests.py
@@ -3,7 +3,7 @@
from django.db.models.query_utils import DeferredAttribute
from django.test import TestCase
-from .models import Secondary, Primary, Child, BigChild
+from .models import Secondary, Primary, Child, BigChild, ChildProxy
class DeferTests(TestCase):
@@ -145,3 +145,7 @@ def test_defer(self):
obj.name = "bb"
obj.save()
+ def test_defer_proxy(self):
+ # using select related and only should not result in Exception
+ for obj in ChildProxy.objects.all().select_related().only('id'):
+ continue

0 comments on commit 9d98b9e

Please sign in to comment.