Admin formset validation cannot take submitted model instance into account when form not valid.
|Reported by:||meshy||Owned by:||kamni|
|Severity:||Normal||Keywords:||admin formset validation|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
In the admin, if the validation on an inline formset depends upon the data from the main form it cannot be correctly validated when the main form is not valid. This is because the instance from the incomplete form is not passed into the formset unless it is completely valid. Instead, on add (https://github.com/django/django/blob/1.5.1/django/contrib/admin/options.py#L988-L994), we get a completely blank new instance, or on change (https://github.com/django/django/blob/1.5.1/django/contrib/admin/options.py#L1085-L1091), we are passed the original instance.
I understand that the current way of doing things may stop invalid data being sent to the formsets but I believe, as this is the data that has been submitted, and the majority of it will likely be correct, that this would be better than the nothing we currently get.
I propose that lines 994 and 1091 both change to new_object = form.instance. This would mean that in a fair number of cases the errors on the main form would not need to be fixed before the errors on the inline form become visible.
I hope that my concerns/intention are clear, but if not, please ask and I will produce a working example and patch for examination.
Change History (21)
comment:1 Changed 3 years ago by mjtamlyn
- Component changed from Uncategorized to contrib.admin
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
- Type changed from Uncategorized to Bug
comment:2 Changed 3 years ago by kamni
- Owner changed from nobody to kamni
- Status changed from new to assigned