Opened 7 years ago

Closed 7 years ago

#28321 closed Cleanup/optimization (fixed)

FormSet.full_clean() shouldn't validate deleted forms

Reported by: Peter Inglesby Owned by: Windson yang
Component: Forms Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django validates all forms in a formset, including those which have been deleted by the user. This means that a formset's .errors attribute can contain reports of errors that don't actually matter.

I'd argue that this violates the principle of least surprise, and that for a deleted form with errors, an empty dict should be added to ._errors in a formset's full_clean().

At the very least this is a documentation bug, since https://docs.djangoproject.com/en/1.11/topics/forms/formsets/#custom-formset-validation suggests not continuing with a call to clean() if a formset has any errors.

Change History (4)

comment:1 by Tim Graham, 7 years ago

Summary: Errors on deleted forms shouldn't be included in a formset's errorsFormSet.full_clean() shouldn't validate deleted forms
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Indeed, it looks inconsistent that BaseFormSet.is_valid() calls _should_delete_form() but full_clean() doesn't.

comment:2 by Windson yang, 7 years ago

Owner: changed from nobody to Windson yang
Status: newassigned

comment:3 by Tim Graham, 7 years ago

Has patch: set
Needs tests: set

PR (without a test)

comment:4 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In f32d246:

Fixed #28321 -- Prevented FormSet.full_clean() from adding errors from deleted forms.

Note: See TracTickets for help on using tickets.
Back to Top