Form validation is bypassed on Admin Inline ModelForms that define extra fields
|Reported by:||izzaddin.ruhulessin@…||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When defining extra/overridden fields on modelforms, validation is bypassed. This can lead to errors under some circumstances.
For example, you have a model 'Book' that defines a ForeignKey to 'Author' named 'author'. On your ModelForm you replace this field by a CharField (or some other type) for whatever reason.
On submitting an invalid form, a ValueError will be raised complaining that the datatype is incorrect.
My proposed solution is overriding ModelForm._post_clean():
class ModelForm(BaseModelForm): def _post_clean(self): if len(self._errors) == 0: super(ModelForm, self)._post_clean()
Change History (10)
comment:1 Changed 4 years ago by melinath
- Component changed from Forms to Documentation
- Needs documentation set
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
- Type changed from Bug to Cleanup/optimization
- Version changed from 1.2 to SVN
Changed 4 years ago by PieterSwinkels
Changed 3 years ago by krzysiumed
comment:7 Changed 3 years ago by Tim Graham <timograham@…>
- Resolution set to fixed
- Status changed from new to closed