1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #36432 -- Fixed a prefetch_related crash on related target subclass queryset.

Regression in 626d77e52a.

Refs #36116.

Thanks Cornelis Poppema for the excellent report.
This commit is contained in:
Simon Charette
2025-06-03 22:34:39 -04:00
committed by Sarah Boyce
parent c075508b4d
commit 08187c94ed
4 changed files with 25 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ from .models import (
Qualification,
Reader,
Room,
SelfDirectedEmployee,
TaggedItem,
Teacher,
WordEntry,
@@ -433,6 +434,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):