How to handle invalid deleted forms in formsets

215 views
Skip to first unread message

Tomi Pieviläinen

unread,
Aug 9, 2010, 8:23:33 AM8/9/10
to Django users
(Using formset_factory, if that makes a difference)

If the user fills a form in formset incompletely and then marks it for
deletion, my form handling dies horribly. The deleted forms prevent
formset.cleaned_data from working as they don't validate and thus the
form doesn't have a cleaned_data attribute. If I try to iterate over
formset.deleted_forms and delete the forms from formset.forms, then
formset.cleaned_data crashes due to index out of range.

How should I be handling these invalid forms the user didn't want
anyway?

Karen Tracey

unread,
Aug 10, 2010, 8:09:11 AM8/10/10
to django...@googlegroups.com
What version of Django? This sounds a lot like:

http://code.djangoproject.com/ticket/11801

which should be fixed in latest 1.1.X and 1.2.X.

Karen
--
http://tracey.org/kmt/

Tomi Pieviläinen

unread,
Aug 10, 2010, 8:17:51 AM8/10/10
to Django users

> What version of Django? This sounds a lot like:

Latest (installed by making pip require django>=1.2).

> http://code.djangoproject.com/ticket/11801

It isn't. The problem is not that I'm not getting
formset.deleted_forms, I am. The problem is that these deleted forms
also go to the cleaned_data, which breaks down because the deleted
forms do not validate, thus they don't have form.cleaned_data that the
formset tries to access.

But what can I do with the fs.deleted_forms? If I try to remove them
from the fs.forms before accessing fs.cleaned_data, the access will
break with array out of bounds, as mentioned.
Reply all
Reply to author
Forward
0 new messages