﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18912	ModelForm doesn't handle unique checks for parent models.	Sebastian Noack	nobody	"The unique checks performed by the !ModelForm class, do not handle parent models. Unique fields inherited from a parent model are checked the same way as direct unique fields and therefore erroneously validates if there is a conflict in the parent model without a related object of the derived model.

{{{#!python
class Animal(models.Model):
    name = models.CharField(max_length=100, unique=True)

class Mammal(Animal):
    pass

class Bird(Animal):
    pass

Bird.objects.create(name='Kiwi')

class MammalForm(ModelForm):
    class Meta:
        model = Mammal

form = MammalForm({'name': 'Kiwi'})
if form.is_valid(): # Returns true, as there is no Mammal with the name 'Kiwi'.
    form.save()     # Raises IntegrityError, because of there is already an Animal with the name 'Kiwi'.
}}}

Also unique_together definitions of parent models are completely ignored.

{{{#!python
class Animal(models.Model):
    type = models.IntegerField(choices=((1, 'Mammal'), (2, 'Bird')))
    name = models.CharField(max_length=100)

    class Meta:
        unique_together = (('type', 'name'),)

class Mammal(Animal):
    pass

class Bird(Animal):
    pass

Mammal.objects.create(type=1, name='Cat')

class MammalForm(ModelForm):
    class Meta:
        model = Mammal

form = MammalForm({'type': 1, 'name': 'Cat'})
if form.is_valid(): # Returns true, because of unique_together definitions from parent models are ignored.
    form.save()     # Raises IntegrityError, because of there is already an Animal of type 1 (Mammal) and the name 'Cat'.
}}}

My patch will fix that behavior, making validation fail in the cases above."	Bug	closed	Forms		Normal	worksforme			Unreviewed	1	0	0	0	0	0
