Opened 15 years ago

Closed 11 years ago

Last modified 11 years ago

#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)

formset_non_form_errors.diff (521 bytes ) - added by vbmendes 15 years ago.
First patch

Download all attachments as: .zip

Change History (12)

by vbmendes, 15 years ago

First patch

comment:1 by anonymous, 15 years ago

Cc: vbmendes@… added

comment:2 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Julien Phalip, 13 years ago

Needs tests: set
Severity: Normal
Type: Bug

comment:4 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 by senko, 11 years ago

Owner: changed from nobody to senko
Status: newassigned

comment:7 by senko, 11 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 Tome Cvitan, 11 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Tome Cvitan, 11 years ago

I have reviewed the solution, looks good as far as I can see.

comment:10 by Senko Rasic <senko.rasic@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 493aca453aa94f160764d9a89c8043f7c9a67a78:

Fixed #11160 - Ensure full_clean is called from non_form_errors

Updated FormSet.non_form_errors() to ensure full_clean() has
been called before returning the errors.

comment:11 by Andrew Godwin <andrew@…>, 11 years ago

In 04e0fc029f6868221dbba850e5a8830c8d11c42c:

Merge pull request #1094 from senko/ticket_11160

Fixed #11160: Formset non_form_errors returns ErrorList() if is_valid is not called

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