Admin formset validation cannot take submitted model instance into account when form not valid.
|Reported by:||Charlie Denton||Owned by:||kamni|
|Severity:||Normal||Keywords:||admin formset validation|
|Cc:||Daniele Procida||Triage Stage:||Accepted|
|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
|Component:||Uncategorized → contrib.admin|
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Accepted|
|Type:||Uncategorized → Bug|