1
0
mirror of https://github.com/django/django.git synced 2025-10-29 00:26:07 +00:00

[5.2.x] Fixed #36432 -- Fixed a prefetch_related crash on related target subclass queryset.

Regression in 626d77e52a.

Refs #36116.

Thanks Cornelis Poppema for the excellent report.

Backport of 08187c94ed from main.
This commit is contained in:
Simon Charette
2025-06-03 22:34:39 -04:00
committed by Sarah Boyce
parent 0c548e62d0
commit 3340d41446
4 changed files with 25 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ from .models import (
Qualification,
Reader,
Room,
SelfDirectedEmployee,
TaggedItem,
Teacher,
WordEntry,
@@ -435,6 +436,18 @@ class PrefetchRelatedTests(TestDataMixin, TestCase):
authors[1].active_favorite_authors, [self.author3, self.author4]
)
def test_prefetch_queryset_child_class(self):
employee = SelfDirectedEmployee.objects.create(name="Foo")
employee.boss = employee
employee.save()
with self.assertNumQueries(2):
retrieved_employee = SelfDirectedEmployee.objects.prefetch_related(
Prefetch("boss", SelfDirectedEmployee.objects.all())
).get()
with self.assertNumQueries(0):
self.assertEqual(retrieved_employee, employee)
self.assertEqual(retrieved_employee.boss, retrieved_employee)
class RawQuerySetTests(TestDataMixin, TestCase):
def test_basic(self):