Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#18574 closed Bug (fixed)

`BaseFormSet.is_valid` should call it's underlying forms' `is_valid`

Reported by: Simon Charette Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal Keywords: form formset is_valid
Cc: foonicorn 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

The actual implementation of BaseFormSet.is_valid checks if any of it's underlying forms have errors which short circuits any extra check-ups that could be defined in the form is_valid method.

i,e.

class MyForm(Form):

  def is_valid(self):
    is_valid = super(MyForm, self).is_valid()
    print 'I was called'
    return is_valid and self.other_non_field_related_validation()

MyFormSet = formset_factory(MyForm)

# In this case calling MyFormSet(data).is_valid() will never print 'I was called'.

I'm submitting this as a bug since I don't think that's the expected behaviour.

Attachments (1)

18574_2.diff (2.3 KB ) - added by foonicorn 11 years ago.
Tests for charettes' patch

Download all attachments as: .zip

Change History (9)

comment:1 by Simon Charette, 12 years ago

Created a pull request which passes all tests on sqlite.

comment:2 by Simon Charette, 12 years ago

Has patch: set

comment:3 by Claude Paroz, 12 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

comment:4 by Simon Charette, 12 years ago

Here's the workaround I use while this is not fixed:

from django.forms.formsets import BaseFormSet


class BaseValidateFormSet(BaseFormSet):
    
    def is_valid(self):
        is_valid = super(BaseValidateFormSet, self).is_valid()
        for form in self:
            is_valid &= form.is_valid() or (self.can_delete and
                                            self._should_delete_form(form))
        return is_valid

by foonicorn, 11 years ago

Attachment: 18574_2.diff added

Tests for charettes' patch

comment:5 by foonicorn, 11 years ago

Cc: foonicorn added
Needs tests: unset

comment:6 by Claude Paroz, 11 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Claude Paroz <claude@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 66dfcc10b37120638894cb412a15274b17cfb360:

Fixed #18574 -- Make BaseFormSet.is_valid call its underlying forms' is_valid

Thanks Simon Charette for the report and the initial patch.

comment:8 by Claude Paroz <claude@…>, 11 years ago

In 67bddc0b7b6468abe875f30e4b70560787b5eb5b:

[1.5.x] Fixed #18574 -- Make BaseFormSet.is_valid call its underlying forms' is_valid

Thanks Simon Charette for the report and the initial patch.
Backport of 66dfcc10b from master.

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