#14642: IndexError: list index out of range caused by inline formsets
------------------------------------+--------------------------------------
               Reporter:  simon@…   |        Owner:  nobody
                 Status:  new       |    Milestone:  1.3
              Component:  Forms     |      Version:  1.2
             Resolution:            |     Keywords:  save_as generic inline
           Triage Stage:  Accepted  |    Has patch:  0
    Needs documentation:  0         |  Needs tests:  0
Patch needs improvement:  0         |
------------------------------------+--------------------------------------
Changes (by poswald):

 * cc: poswald (added)


Comment:

 I believe I have a fully reproduceable version of this issue. For me it
 comes when there is discrepancy between the form submitted and the
 database. I was getting this error in my production system and I thought
 it was my forms. Turns out I could eliminate my forms as a source of the
 issue by using the admin. I've changed the summary to match. I reduced it
 down to this test case in Django 1.2.4:


 models.py:
 {{{
 class Thingy(models.Model):
     description = models.CharField(max_length=256)

 class ThingyItem(models.Model):
     thingy = models.ForeignKey(Thingy)
     description = models.CharField(max_length=256)
 }}}


 admin.py:

 {{{
 class ThingyItemInline(admin.TabularInline):
     model = ThingyItem
     extra = 0

 class ThingyAdmin(admin.ModelAdmin):
     inlines = [ThingyItemInline,]

 admin.site.register(Thingy, ThingyAdmin)
 admin.site.register(ThingyItem)
 }}}

 Now do the following:

 * Create a new Thingy with several ThingyItems in the admin and save it.
 * Open the edit page.
 * Open the edit page for the same thingy in a second browser window.
 * Check the "Delete" button on the last ThingyItem and save it in the
 second window.
 * Now go back to the first form and save it

 When I do this, I get:

 {{{
 Traceback:
 File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-
 packages/django/core/handlers/base.py" in get_response
   100.                     response = callback(request, *callback_args,
 **callback_kwargs)

 ... snipped because it's the same as above ...

 File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-
 packages/django/db/models/query.py" in __getitem__
   171.             return self._result_cache[k]

 Exception Type: IndexError at /admin/exampletest/thingy/1/unhandled
 Exception Value: list index out of range
 }}}

 It seems that the inline formset code is a bit brittle. An error is thrown
 when the data submitted in the management form is not in agreement with
 the state of the database. I'd like to make an automated test case for
 this but I'm not sure how to do that sequence of steps in the test client.
 If anyone can shed some light onto what the formset code is *supposed* to
 do in this situation it would be useful. I imagine the options are the
 second form overrides the first or something like a form validation error
 is raised that indicates the form is stale.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14642#comment:9>
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.

Reply via email to