Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#12295 closed (fixed)

A formset with no forms does not call self.clean() when self.is_valid() is called.

Reported by: tomevans222 Owned by: nobody
Component: Forms Version: 1.1
Severity: Keywords: formset sprintSep2010
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Test case:

from django import forms
from django.forms.formsets import BaseFormSet, formset_factory

class EmptyFsetWontValidate(BaseFormSet):
  def clean(self):
    raise forms.ValidationError, "Clean method called"

class SimpleForm(forms.Form):
  name = forms.CharField()

EmptyFsetWontValidateFormset = formset_factory(SimpleForm, extra=0, formset=EmptyFsetWontValidate)
formset = EmptyFsetWontValidateFormset({'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'0'})
formset2 = EmptyFsetWontValidateFormset({'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'1', 'form-0-name':'bah' })

# will return True
formset.is_valid()
# will return False
formset2.is_valid()
# But examine formset.errors...
formset.errors
# and now is_valid() will return False
formset.is_valid()

Test case is pretty straightforward. Trivial patch is attached.

Attachments (2)

trivial.diff (467 bytes ) - added by tomevans222 14 years ago.
empty-formset-is-not-valid-with-unittests.diff (2.2 KB ) - added by David Novakovic 14 years ago.

Download all attachments as: .zip

Change History (8)

by tomevans222, 14 years ago

Attachment: trivial.diff added

comment:1 by tomevans222, 14 years ago

Has patch: set

comment:2 by Jeremy Dunck, 14 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

This patch still needs tests, no matter how trivial the test case might be.

comment:3 by David Novakovic, 14 years ago

Attaching updated patch that includes unit tests.

by David Novakovic, 14 years ago

comment:4 by Mark Lavin, 14 years ago

Keywords: sprintSep2010 added
Triage Stage: AcceptedReady for checkin

This patch works for me as on [13738] and looks ready for check in.

comment:5 by Andrew Godwin, 13 years ago

Resolution: fixed
Status: newclosed

(In [15158]) Fixed #12295 -- Issue had already been fixed, but added test. Thanks tomevans222 and dpn.

comment:6 by Andrew Godwin, 13 years ago

(In [15159]) Fixed #12295 -- Issue had already been fixed, but added test. Thanks tomevans222 and dpn.

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