1
0
mirror of https://github.com/django/django.git synced 2025-10-27 15:46:10 +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

@@ -2678,7 +2678,11 @@ class RelatedPopulator:
)
self.model_cls = klass_info["model"]
self.pk_idx = self.init_list.index(self.model_cls._meta.pk.attname)
# A primary key must have all of its constituents not-NULL as
# NULL != NULL and thus NULL cannot be referenced through a foreign
# relationship. Therefore checking for a single member of the primary
# key is enough to determine if the referenced object exists or not.
self.pk_idx = self.init_list.index(self.model_cls._meta.pk_fields[0].attname)
self.related_populators = get_related_populators(klass_info, select, self.db)
self.local_setter = klass_info["local_setter"]
self.remote_setter = klass_info["remote_setter"]