Opened 7 years ago

Closed 5 years ago

Last modified 5 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: UI/UX:


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
# will return False
# But examine formset.errors...
# and now is_valid() will return False

Test case is pretty straightforward. Trivial patch is attached.

Attachments (2)

trivial.diff (467 bytes) - added by tomevans222 7 years ago.
empty-formset-is-not-valid-with-unittests.diff (2.2 KB) - added by dpn 6 years ago.

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by tomevans222

comment:1 Changed 6 years ago by tomevans222

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by jdunck

  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

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

comment:3 Changed 6 years ago by dpn

Attaching updated patch that includes unit tests.

comment:4 Changed 6 years ago by mlavin

  • Keywords sprintSep2010 added
  • Triage Stage changed from Accepted to Ready for checkin

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

comment:5 Changed 5 years ago by andrewgodwin

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:6 Changed 5 years ago by andrewgodwin

(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