Unique constraint error with model inheritance while ModelForm should not validate
|Reported by:||fgaudin||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.1|
|Severity:||Keywords:||unique constraint, ModelForm, inheritance|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The use case is :
- ParentClass has an attribute "name" with unique=True
- FirstSubClass inherits ParentClass
- SecondSubClass inherits ParentClass
With a ModelForm for each subclass, I can't create two FirstSubClasses with the same name, neither two SecondSubClasses, the form doesn't validate, what is expected.
But if I create a FirstSubClass instance and try to create a SecondSubClass instance, the form validate and unique constraint error is raised by postgres.
A project showing the use case with unit tests is in attachment.
Change History (13)
Changed 6 years ago by fgaudin
comment:1 Changed 6 years ago by fgaudin
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 6 years ago by kmtracey
- Component changed from Forms to Database layer (models, ORM)
- milestone set to 1.2
- Triage Stage changed from Unreviewed to Accepted