#11160 closed Bug (fixed)
Formset non_form_errors returns ErrorList() if is_valid is not called
Reported by: | vbmendes | Owned by: | senko |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | formset non_form_errors validation |
Cc: | vbmendes@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If Formset.non_form_errors() is called before Formset.is_valid(), it will return an empty ErrorList.
Let's pretend we have two formsets in one view and we make this test: if formset1.is_valid() and formset2.is_valid(). If formset1 is not valid, formset2's is_valid() will not be called. It means that the user will have to fix all the formset1's validation erros before knowing that formset2 also has errors. It's annoying for the user.
I wrote a little patch to fix this issue. Just changing a little the Formset.non_form_errors() function.
Attachments (1)
Change History (12)
by , 15 years ago
Attachment: | formset_non_form_errors.diff added |
---|
comment:1 by , 15 years ago
Cc: | added |
---|
comment:2 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 14 years ago
Needs tests: | set |
---|---|
Severity: | → Normal |
Type: | → Bug |
comment:6 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 12 years ago
Needs tests: | unset |
---|
The patch "formset_non_form_errors.diff" doesn't do enough, because if non_form_errors() is called multiple times for any reasons, and there weren't any non-form errors, it will attempt the validation multiple times.
The fix I got in a pull request at https://github.com/django/django/pull/1094 is slightly different: full_clean() always sets the _non_form_errors (either to an empty error list, or to the actual errors if there are any), and non_field_errors() just check whether it needs to run full_clean() beforehand.
comment:8 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:10 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
First patch