From 4bbe8261c402694a1da3efcaafe3332f9c57af15 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Wed, 8 Apr 2020 14:38:35 +0200 Subject: [PATCH] Fixed #31437 -- Corrected tests to show abstract multiple inheritance system check error. Added minimal multiple inheritance test case showing error. Removed obsolete diamond-inheritance case, originally added in 85ef98dc6ec565b1add417bd76808664e7318026. --- .../test_abstract_inheritance.py | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/tests/model_inheritance/test_abstract_inheritance.py b/tests/model_inheritance/test_abstract_inheritance.py index dfcd47c111..1293efc531 100644 --- a/tests/model_inheritance/test_abstract_inheritance.py +++ b/tests/model_inheritance/test_abstract_inheritance.py @@ -34,33 +34,30 @@ class AbstractInheritanceTests(SimpleTestCase): self.assertEqual(DerivedChild._meta.get_field('name').max_length, 50) self.assertEqual(DerivedGrandChild._meta.get_field('name').max_length, 50) - def test_multiple_parents_mro(self): - class AbstractBaseOne(models.Model): - class Meta: - abstract = True - - class AbstractBaseTwo(models.Model): - name = models.CharField(max_length=30) + def test_multiple_inheritance_cannot_shadow_inherited_field(self): + class ParentA(models.Model): + name = models.CharField(max_length=255) class Meta: abstract = True - class DescendantOne(AbstractBaseOne, AbstractBaseTwo): - class Meta: - abstract = True - - class DescendantTwo(AbstractBaseOne, AbstractBaseTwo): - name = models.CharField(max_length=50) + class ParentB(models.Model): + name = models.IntegerField() class Meta: abstract = True - class Derived(DescendantOne, DescendantTwo): + class Child(ParentA, ParentB): pass - self.assertEqual(DescendantOne._meta.get_field('name').max_length, 30) - self.assertEqual(DescendantTwo._meta.get_field('name').max_length, 50) - self.assertEqual(Derived._meta.get_field('name').max_length, 50) + self.assertEqual(Child.check(), [ + Error( + "The field 'name' clashes with the field 'name' from model " + "'model_inheritance.child'.", + obj=Child._meta.get_field('name'), + id='models.E006', + ), + ]) def test_multiple_inheritance_cannot_shadow_concrete_inherited_field(self): class ConcreteParent(models.Model):