summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHal Blackburn <hwtb2@cam.ac.uk>2025-11-04 05:58:46 +0000
committerJacob Walls <jacobtylerwalls@gmail.com>2025-11-04 11:59:49 -0500
commit12042b8978a686d815636b11b9ea602b7031ae0a (patch)
treeab87720bd75d2ca8699831af4f3998f139519a22 /tests
parent1b9f7a1ddf1ab84ade602423c8cde69b8404286d (diff)
[6.0.x] Fixed #36704 -- Fixed system check error for proxy model with a composite pk.
Proxy models subclassing a model with a CompositePrimaryKey were incorrectly reporting check errors because the check that requires only local fields to be used in a composite pk was evaluated against the proxy subclass, which has no fields. To fix this, composite pk field checks are not evaluated against proxy subclasses, as none of the checks are applicable to proxy subclasses. This also has the benefit of not double-reporting real check errors from an invalid superclass pk. Thanks Clifford Gama for the review. Backport of 74564946c3b42a2ef7d087047e49873847a7e1d9 from main.
Diffstat (limited to 'tests')
-rw-r--r--tests/composite_pk/test_checks.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/composite_pk/test_checks.py b/tests/composite_pk/test_checks.py
index c33f2ee2eb..21796aa871 100644
--- a/tests/composite_pk/test_checks.py
+++ b/tests/composite_pk/test_checks.py
@@ -268,3 +268,38 @@ class CompositePKChecksTests(TestCase):
),
],
)
+
+ def test_proxy_model_can_subclass_model_with_composite_pk(self):
+ class Foo(models.Model):
+ pk = models.CompositePrimaryKey("a", "b")
+ a = models.SmallIntegerField()
+ b = models.SmallIntegerField()
+
+ class Bar(Foo):
+ class Meta:
+ proxy = True
+
+ self.assertEqual(Foo.check(databases=self.databases), [])
+ self.assertEqual(Bar.check(databases=self.databases), [])
+
+ def test_proxy_model_does_not_check_superclass_composite_pk_errors(self):
+ class Foo(models.Model):
+ pk = models.CompositePrimaryKey("a", "b")
+ a = models.SmallIntegerField()
+
+ class Bar(Foo):
+ class Meta:
+ proxy = True
+
+ self.assertEqual(
+ Foo.check(databases=self.databases),
+ [
+ checks.Error(
+ "'b' cannot be included in the composite primary key.",
+ hint="'b' is not a valid field.",
+ obj=Foo,
+ id="models.E042",
+ ),
+ ],
+ )
+ self.assertEqual(Bar.check(databases=self.databases), [])