#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)
Change History (8)
by , 16 years ago
| Attachment: | trivial.diff added |
|---|
comment:1 by , 16 years ago
| Has patch: | set |
|---|
comment:2 by , 16 years ago
| Needs tests: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
by , 15 years ago
| Attachment: | empty-formset-is-not-valid-with-unittests.diff added |
|---|
comment:4 by , 15 years ago
| Keywords: | sprintSep2010 added |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
This patch works for me as on [13738] and looks ready for check in.
comment:5 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:6 by , 15 years ago
Note:
See TracTickets
for help on using tickets.
This patch still needs tests, no matter how trivial the test case might be.