#15574: IndexError: list index out of range caused by inline formsets
-------------------------------------+-------------------------------------
     Reporter:  poswald              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Forms                |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  inline formset       |             Triage Stage:  Design
    Has patch:  1                    |  decision needed
  Needs tests:  0                    |      Needs documentation:  0
Easy pickings:  0                    |  Patch needs improvement:  0
                                     |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by chriscog):

 Just ran into this issue myself, and reported in #19408. I get the
 "IndexError" if I was to simultaneously delete the last item in a formset,
 but get an uncaught ValidationError exception - uncaught, in that it
 returns a 500 code rather than a redbox in the form, if I simultaneously
 delete middle items.

 I agree that there's no real good solution, here.

 Clearly if there's simultaneous deletes, then "WELL, NOT A PROBLEM".
 However, if one form attempts a delete, and the other an edit, then it's
 not so clear. The best solution would be to come up with some kind of
 validation error for the subsequent attempt, but what, exactly, to display
 is the question. However, given that there is currently NO checking for
 simultaneous edits. (the 2nd submitted edits will override the first), I
 think its safe to say that we don't have to be "Perfect" here... if
 someone wants perfection, then they're going to have to arrange some kind
 of funky locking themselves, and Django should be relied on to just "do
 something that makes sense".

 So, in that vein, here's my proposal:

 1. No matter what, Django should cope with the case that a row disappears,
 so the "IndexError" should never happen.

 2. A delete followed by a re-delete on the same form results in a delete
 with no warning.

 3. A delete followed by an edit results in a validation error for the
 second action, the edit. However, since the row is _gone_, the error is an
 error on the form set saying that "<Object x> has been recently deleted,
 and your edits have been discarded". Simply re-submitting the form will
 now work.

 4. An edit followed by a delete (if this can even be detected) results in
 a validation error on the form being deleted. The form shows the post-edit
 values. The message is "<Object x> has recently been changed. You may
 attempt to re-delete it."

 5. An edit followed by an edit (again, if this is even detected) will just
 save the new edits. Given the "absolute best option" would be to somehow
 show the newly-changed values while keeping the user's edits so he can
 validate it is a very tall order, I would just fall back on saving the 2nd
 set of edits, and making this behaviour well documented.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/15574#comment:20>
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.


Reply via email to