Form validation is bypassed on Admin Inline ModelForms that define extra fields
|Reported by:||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 5 years ago by
|Component:||Forms → Documentation|
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Accepted|
|Type:||Bug → Cleanup/optimization|
|Version:||1.2 → SVN|