title: How to debug a Django MultiValueDictKeyError on Formset POST
body: <p>When I post my formset, I get a MultiValueDictKeyError.  Specifically:</p>
  
  <pre><code>MultiValueDictKeyError at /core/customers/1/update/documents/
  "Key u'documents-0-attachment_ptr' not found in &lt;QueryDict: {u'documents-1-last_modified_date': [u''], u'documents-1-name': [u''], u'documents-MAX_NUM_FORMS': [u''], u'documents-0-attachment_file': [u''], u'documents-INITIAL_FORMS': [u'1'], u'documents-1-document_type': [u''], u'documents-0-notes': [u''], u'documents-1-notes': [u''], u'submit': [u'Submit changes'], u'documents-0-DELETE': [u'on'], u'documents-1-attachment_file': [u''], u'documents-0-document_type': [u''], u'documents-TOTAL_FORMS': [u'2'], u'documents-0-name': [u'test'], u'documents-1-creation_date': [u''], u'documents-0-creation_date': [u'2012-12-01 23:41:48'], u'csrfmiddlewaretoken': [u'NCQ15jA7erX5dAbx20Scr3gWxgaTn3Iq', u'NCQ15jA7erX5dAbx20Scr3gWxgaTn3Iq', u'NCQ15jA7erX5dAbx20Scr3gWxgaTn3Iq'], u'documents-0-last_modified_date': [u'2012-12-01 23:41:48']}&gt;"
  </code></pre>
  
  <p>The key part is that Django is looking for the key <code>documents-0-attachment_ptr</code> in the post data.  This is confusing -- a Document is a subclass of an Attachment.  All of the other post data is as expected.  Why is Django needing pointer data in my formset?</p>
  
  <p>Here is the form used in the formset:</p>
  
  <pre><code>class DocumentInlineForm(forms.ModelForm):  # pylint: disable=R0924
      attachment_file = forms.FileField(widget=NoDirectoryClearableFileInput)
      notes = forms.CharField(
          required=False,
          widget=forms.Textarea(attrs={'rows': 2,}), 
      )
      helper = DocumentInlineFormHelper()
  
      class Meta: # pylint: disable=W0232,R0903
          fields = (
              'attachment_file', 
              'creation_date',
              'document_type',
              'last_modified_date',
              'name',
              'notes',
          )
          model = Document
  </code></pre>
  
  <p>And here is the Document model:</p>
  
  <pre><code>"""
  Handles document model definitions.
  """
  from django.db import models
  from eee_core.models.attachments import Attachment
  from django.db.models.signals import pre_save
  from datetime import datetime
  from django.utils.timezone import utc
  
  class Document(Attachment):
      """
      A document is an attachment with additional meta data.
      """
      creation_date = models.DateTimeField(
          blank=True, 
          null=True,
      )
      document_type = models.CharField(
          blank=True, 
          choices=(
              ('CONTRACT', 'Contract'),
              ('INVOICE', 'Invoice'),
              ('FACILITY', 'Facility change form'),
              ('LOA', 'Letter of authorization'),
              ('USAGE', 'Usage history document'),
              ('OTHER', 'Other'),
          ),
          default=None, 
          null=True, 
          max_length=8, 
      )
      last_modified_date = models.DateTimeField(
          blank=True, 
          null=True,
      )
      notes = models.TextField(
          blank=True,
          null=True,
      )
  
      class Meta(Attachment.Meta): # pylint: disable=W0232,R0903
          """
          Sets meta fields for model.
          """
          app_label = 'core'
  
      def __str__(self):
          return unicode(self).encode('utf-8')
  
      def __unicode__(self):
          return unicode(self.name)
  
  def pre_save_callback(sender, instance, *args, **kwargs): # pylint: disable=W0613
      if not isinstance(instance, Document):
          return
  
      if not instance.creation_date:
          instance.creation_date = datetime.utcnow().replace(tzinfo=utc)
  
      instance.last_modified_date = datetime.utcnow().replace(tzinfo=utc)
  
  pre_save.connect(pre_save_callback, dispatch_uid='document_pre_save')
  </code></pre>
  
  <p><strong>Additional info:</strong></p>
  
  <p>Curiously, the inital post of the formset works fine.  It is only on update posts -- when there are initial forms in the formset -- when I get this error.  It also happens when I try to delete forms from the formset.</p>
  
  <p>Also, the formset is a generic inline formset using django crispy forms.</p>
  
  <p><strong>Update</strong></p>
  
  <p>There was a request for the template code used.  Here is the simplified version:</p>
  
  <pre><code>{% load crispy_forms_tags %}
  {% load url from future %}
  &lt;form action="" method="post" enctype="multipart/form-data"&gt;
      {{ formset.management_form }}
      {% for subform in formset.forms %}
        {{ subform.id }}
        {% crispy subform %}
      {% endfor %}
      &lt;div class="btn-toolbar"&gt;
          &lt;input class='btn btn-primary' type="submit" name="submit" value="Submit changes" /&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>