Opened 7 years ago

Closed 6 years ago

Last modified 6 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:

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 7 years ago.
empty-formset-is-not-valid-with-unittests.diff (2.2 KB) - added by David Novakovic 6 years ago.

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by tomevans222

Attachment: trivial.diff added

comment:1 Changed 7 years ago by tomevans222

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

comment:2 Changed 7 years ago by Jeremy Dunck

Needs tests: set
Triage Stage: UnreviewedAccepted

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

comment:3 Changed 6 years ago by David Novakovic

Attaching updated patch that includes unit tests.

Changed 6 years ago by David Novakovic

comment:4 Changed 6 years ago by Mark Lavin

Keywords: sprintSep2010 added
Triage Stage: AcceptedReady for checkin

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

comment:5 Changed 6 years ago by Andrew Godwin

Resolution: fixed
Status: newclosed

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

comment:6 Changed 6 years ago by Andrew Godwin

(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