#19145: valid formset with invalid deleted form raises AttributeError when
trying
to access cleaned_data
-------------------------------+----------------------------------
Reporter: valtron2000@… | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.4
Severity: Normal | Keywords: formset cleaned_data
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+----------------------------------
Example (run in `manage.py shell`):
{{{
from django.forms import Form, BooleanField
from django.forms.formsets import formset_factory
class F(Form):
a = BooleanField()
FS = formset_factory(form = F, can_delete = True)
fs = FS(data = {
'form-MAX_NUM_FORMS': '',
'form-INITIAL_FORMS': '1',
'form-TOTAL_FORMS': '1',
'form-0-a': '',
'form-0-DELETE': 'on',
})
assert fs.is_valid()
# fs.forms[0].cleaned_data raises AttributeError
print fs.cleaned_data
}}}
This can be fixed by changing `BaseFormSet._get_cleaned_data` to only
return the `cleaned_data` of non-deleted forms:
{{{
def _get_cleaned_data(self):
"""
Returns a list of form.cleaned_data dicts for every form in
self.forms.
"""
if not self.is_valid():
raise AttributeError("'%s' object has no attribute 'cleaned_data'"
% self.__class__.__name__)
return [form.cleaned_data for form in self.forms if not
self._should_delete_form(form)]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19145>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.