#11418: formset.cleaned_data raises AttributeError when is_valid is True
-------------------------------+--------------------------------------------
Reporter: adurdin | Owner: mlavin
Status: assigned | Milestone:
Component: Forms | Version: SVN
Resolution: | Keywords:
Stage: Accepted | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
-------------------------------+--------------------------------------------
Changes (by mlavin):
* owner: nobody => mlavin
* status: new => assigned
Comment:
This formset does have a form in it and it is not valid. The formset
itself is bound but the form is not bound (and hence not valid).
{{{
>>> from django import forms
>>> class ArticleForm(forms.Form):
... title = forms.CharField()
... pub_date = forms.DateField()
...
>>> from django.forms.formsets import formset_factory
>>> ArticleFormSet = formset_factory(ArticleForm)
>>> formset = ArticleFormSet({})
>>> formset.forms
[<__main__.ArticleForm object at 0x94636cc>]
>>> formset.forms[0].is_valid()
False
>>> formset.is_bound
True
>>> formset.forms[0].is_bound
False
}}}
I think the problem is in the BaseFormSet._construct_form:
{{{
def _construct_form(self, i, **kwargs):
"""
Instantiates and returns the i-th form instance in a formset.
"""
defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)}
if self.data or self.files:
defaults['data'] = self.data
defaults['files'] = self.files
...
}}}
{{{ if self.data or self.files: }}} should be {{{ if self.is_bound: }}}
because the empty data dictionary is not being passed down to the forms.
--
Ticket URL: <http://code.djangoproject.com/ticket/11418#comment:2>
Django <http://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 this group at
http://groups.google.com/group/django-updates?hl=en.