Fixed -- 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
@@ -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)
-
- class Meta:
- abstract = True
+ def test_multiple_inheritance_cannot_shadow_inherited_field(self):
+ class ParentA(models.Model):
+ name = models.CharField(max_length=255)
- 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):
