1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +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

@@ -14,17 +14,18 @@ class Token(models.Model):
secret = models.CharField(max_length=10, default="", blank=True)
class BaseModel(models.Model):
class AbstractUser(models.Model):
pk = models.CompositePrimaryKey("tenant_id", "id")
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE)
email = models.EmailField(unique=True)
id = models.SmallIntegerField(unique=True)
class Meta:
abstract = True
class User(BaseModel):
email = models.EmailField(unique=True)
class User(AbstractUser):
pass
class Comment(models.Model):
@@ -35,13 +36,14 @@ class Comment(models.Model):
related_name="comments",
)
id = models.SmallIntegerField(unique=True, db_column="comment_id")
user_id = models.SmallIntegerField()
user_id = models.SmallIntegerField(null=True)
user = models.ForeignObject(
User,
on_delete=models.CASCADE,
from_fields=("tenant_id", "user_id"),
to_fields=("tenant_id", "id"),
related_name="comments",
null=True,
)
text = models.TextField(default="", blank=True)
integer = models.IntegerField(default=0)