#18508: Bug in handling out-of-date POST data with inlineformset_factory
----------------------------+--------------------
     Reporter:  olau        |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Forms       |    Version:  1.4
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 Hi, there's a bug in BaseModelFormSet._construct_form. There's a guard
 supposed to take care of bound forms, but if one of the entries has been
 deleted, self._existing_object(pk) will return None so you can end up in

 {{{
         if i < self.initial_form_count() and not kwargs.get('instance'):
             kwargs['instance'] = self.get_queryset()[i]
 }}}

 which is dangerous for a bound form where you must use ids to identify
 elements since element "i" can have changed from when the form was
 generated. In my case, I got an IndexError because there weren't enough
 elements left from a recent deletion.

 I think the correct fix is to change the "if" to an "elif".

 I've attached a patch with this fix and a test case for reproducing the
 problem (there doesn't seem to be any tests of model formsets?).

 Note that the test as entered doesn't pass even with the fix because of
 issue #14877 - if you delete formset.save() and below in the test, it does
 pass.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18508>
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 this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to