1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #36373 -- Fixed select_related() crash on foreign object for a composite pk.

Thanks Jacob Walls for the report and Sarah for the in-depth review.
This commit is contained in:
Simon Charette
2025-05-08 14:02:35 -04:00
committed by Sarah Boyce
parent 42ab99309d
commit 8be0c0d690
4 changed files with 21 additions and 6 deletions

View File

@@ -184,6 +184,14 @@ class CompositePKTests(TestCase):
with self.assertNumQueries(1):
self.assertEqual(user.email, self.user.email)
def test_select_related(self):
Comment.objects.create(tenant=self.tenant, id=2)
with self.assertNumQueries(1):
comments = list(Comment.objects.select_related("user").order_by("pk"))
self.assertEqual(len(comments), 2)
self.assertEqual(comments[0].user, self.user)
self.assertIsNone(comments[1].user)
def test_model_forms(self):
fields = ["tenant", "id", "user_id", "text", "integer"]
self.assertEqual(list(CommentForm.base_fields), fields)