Skip to content

Commit

Permalink
Fixed #33816 -- Fixed QuerySet.only() after select_related() crash on…
Browse files Browse the repository at this point in the history
… proxy models.
  • Loading branch information
ipakeev committed Jul 4, 2022
1 parent 5eb6a2b commit 4257187
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions django/db/models/sql/query.py
Expand Up @@ -748,6 +748,7 @@ def deferred_to_data(self, target):
cur_model = source.related_model
else:
cur_model = source.remote_field.model
cur_model = cur_model._meta.concrete_model
opts = cur_model._meta
# Even if we're "just passing through" this model, we must add
# both the current model's pk and the related reference field
Expand Down
6 changes: 6 additions & 0 deletions tests/proxy_models/tests.py
Expand Up @@ -395,6 +395,12 @@ def test_proxy_load_from_fixture(self):
p = MyPerson.objects.get(pk=100)
self.assertEqual(p.name, "Elvis Presley")

def test_select_related_only(self):
user = ProxyTrackerUser.objects.create(name="Joe Doe", status="test")
issue = Issue.objects.create(summary="New issue", assignee=user)
qs = Issue.objects.select_related("assignee").only("assignee__status")
self.assertEqual(qs.get(), issue)

def test_eq(self):
self.assertEqual(MyPerson(id=100), Person(id=100))

Expand Down

0 comments on commit 4257187

Please sign in to comment.