Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#2045 closed defect (fixed)

TypeError: string indices must be integers

Reported by: amcnabb@… Owned by: adrian
Component: Validators Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I created a manipulator with self.fields = [forms.FileUploadField('exportfile')]

When submitting the form with a file named 'testfile', there is an error message: "TypeError: string indices must be integers". Apparently isNonEmptyFile expects field_data to be a dictionary or something. The bottom of the trace is as follows:

/sw/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/forms/ in isNonEmptyFile


  1. class FileUploadField(FormField):
  2. def init(self, field_name, is_required=False, validator_list=[]):
  3. self.field_name, self.is_required = field_name, is_required
  4. self.validator_list = [self.isNonEmptyFile] + validator_list 642.
  5. def isNonEmptyFile(self, field_data, all_data):
  1. if not field_datacontent?: ...
  1. raise validators.CriticalValidationError, gettext("The submitted file is empty.") 646.
  2. def render(self, data):
  3. return '<input type="file" id="%s" class="v%s" name="%s" />' % \
  4. (self.get_id(),, self.field_name)


▼ Local vars
Variable Value
<MultiValueDict: {'exportfile': ['testfile']}>
FormField "exportfile"

Change History (5)

comment:1 Changed 10 years ago by ubernostrum

Please send questions and general support requests to the Django users mailing list (; this system should only be used once you're certain you've found a bug in Django.

comment:2 Changed 10 years ago by adrian

  • Resolution set to invalid
  • Status changed from new to closed

Closing (see previous comment).

comment:3 Changed 10 years ago by anonymous

  • Resolution invalid deleted
  • Status changed from closed to reopened

In FileUploadField.isNonEmptyFile(), it needs to check if field_data is dictionary-like before doing "if not field_datacontent?". If so, it should give an error that enctype="multipart/form-data" was not specified in the form.

comment:4 Changed 10 years ago by lukeplant

Agreed that this is a real bug (I got caught in it just the other day myself), and the solution needs to take into account the fact that it is possible for an end user to alter a form and submit data how they like. So, even if the developer created his form correctly, an end user could trigger this error. Therefore Django should deal with it in such a way that a backtrace is avoided.

comment:5 Changed 10 years ago by lukeplant

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [3048]) Fixed #2045 - TypeError thrown if a form does not have the correct enctype for uploading
files. It throws a ValidationError now, as it should.

Note: See TracTickets for help on using tickets.
Back to Top