Skip to content

Commit 4bbe826

Browse files
carltongibsonfelixxm
authored andcommitted
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 85ef98d.
1 parent 537b0c5 commit 4bbe826

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

tests/model_inheritance/test_abstract_inheritance.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,30 @@ class DerivedGrandChild(AbstractDescendant):
3434
self.assertEqual(DerivedChild._meta.get_field('name').max_length, 50)
3535
self.assertEqual(DerivedGrandChild._meta.get_field('name').max_length, 50)
3636

37-
def test_multiple_parents_mro(self):
38-
class AbstractBaseOne(models.Model):
39-
class Meta:
40-
abstract = True
41-
42-
class AbstractBaseTwo(models.Model):
43-
name = models.CharField(max_length=30)
44-
45-
class Meta:
46-
abstract = True
37+
def test_multiple_inheritance_cannot_shadow_inherited_field(self):
38+
class ParentA(models.Model):
39+
name = models.CharField(max_length=255)
4740

48-
class DescendantOne(AbstractBaseOne, AbstractBaseTwo):
4941
class Meta:
5042
abstract = True
5143

52-
class DescendantTwo(AbstractBaseOne, AbstractBaseTwo):
53-
name = models.CharField(max_length=50)
44+
class ParentB(models.Model):
45+
name = models.IntegerField()
5446

5547
class Meta:
5648
abstract = True
5749

58-
class Derived(DescendantOne, DescendantTwo):
50+
class Child(ParentA, ParentB):
5951
pass
6052

61-
self.assertEqual(DescendantOne._meta.get_field('name').max_length, 30)
62-
self.assertEqual(DescendantTwo._meta.get_field('name').max_length, 50)
63-
self.assertEqual(Derived._meta.get_field('name').max_length, 50)
53+
self.assertEqual(Child.check(), [
54+
Error(
55+
"The field 'name' clashes with the field 'name' from model "
56+
"'model_inheritance.child'.",
57+
obj=Child._meta.get_field('name'),
58+
id='models.E006',
59+
),
60+
])
6461

6562
def test_multiple_inheritance_cannot_shadow_concrete_inherited_field(self):
6663
class ConcreteParent(models.Model):

0 commit comments

Comments
 (0)