diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index c29673e..57dbfa4 100644
a
|
b
|
class Query(object):
|
549 | 549 | columns = set() |
550 | 550 | orig_opts = self.model._meta |
551 | 551 | seen = {} |
552 | | must_include = {self.model: set([orig_opts.pk])} |
| 552 | if orig_opts.proxy: |
| 553 | must_include = {orig_opts.proxy_for_model: set([orig_opts.pk])} |
| 554 | else: |
| 555 | must_include = {self.model: set([orig_opts.pk])} |
553 | 556 | for field_name in field_names: |
554 | 557 | parts = field_name.split(LOOKUP_SEP) |
555 | 558 | cur_model = self.model |
diff --git a/tests/regressiontests/defer_regress/models.py b/tests/regressiontests/defer_regress/models.py
index 8db8c29..4e4ab0a 100644
a
|
b
|
class Leaf(models.Model):
|
34 | 34 | class ResolveThis(models.Model): |
35 | 35 | num = models.FloatField() |
36 | 36 | name = models.CharField(max_length=16) |
| 37 | |
| 38 | class Proxy(Item): |
| 39 | class Meta: |
| 40 | proxy = True |
diff --git a/tests/regressiontests/defer_regress/tests.py b/tests/regressiontests/defer_regress/tests.py
index 6f1b023..820aec8 100644
a
|
b
|
from django.db import connection
|
7 | 7 | from django.db.models.loading import cache |
8 | 8 | from django.test import TestCase |
9 | 9 | |
10 | | from models import ResolveThis, Item, RelatedItem, Child, Leaf |
| 10 | from models import ResolveThis, Item, RelatedItem, Child, Leaf, Proxy |
11 | 11 | |
12 | 12 | |
13 | 13 | class DeferRegressionTest(TestCase): |
… |
… |
class DeferRegressionTest(TestCase):
|
111 | 111 | Child, |
112 | 112 | Item, |
113 | 113 | Leaf, |
| 114 | Proxy, |
114 | 115 | RelatedItem, |
115 | 116 | ResolveThis, |
116 | 117 | ] |
… |
… |
class DeferRegressionTest(TestCase):
|
139 | 140 | "Leaf_Deferred_name_value", |
140 | 141 | "Leaf_Deferred_second_child_value", |
141 | 142 | "Leaf_Deferred_value", |
| 143 | "Proxy", |
142 | 144 | "RelatedItem", |
143 | 145 | "RelatedItem_Deferred_", |
144 | 146 | "RelatedItem_Deferred_item_id", |
… |
… |
class DeferRegressionTest(TestCase):
|
146 | 148 | ] |
147 | 149 | ) |
148 | 150 | |
| 151 | # Regression for #15790 - only() broken for proxy models |
| 152 | proxy = Proxy.objects.create(name="proxy", value=42) |
| 153 | deferredproxy = Proxy.objects.only('other_value').get(pk=proxy.pk) |
| 154 | self.assertEqual(deferredproxy.name, proxy.name) |
| 155 | self.assertEqual(deferredproxy.value, proxy.value) |
| 156 | |
149 | 157 | def test_resolve_columns(self): |
150 | 158 | rt = ResolveThis.objects.create(num=5.0, name='Foobar') |
151 | 159 | qs = ResolveThis.objects.defer('num') |