Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#2045 closed defect (fixed)

TypeError: string indices must be integers

Reported by: amcnabb@… Owned by: Adrian Holovaty
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: no UI/UX: no

Description

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/init.py in isNonEmptyFile

637.

  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.class.name, self.field_name)

650.

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

Change History (5)

comment:1 by James Bennett, 18 years ago

Please send questions and general support requests to the Django users mailing list (http://groups.google.com/group/django-users/); this system should only be used once you're certain you've found a bug in Django.

comment:2 by Adrian Holovaty, 18 years ago

Resolution: invalid
Status: newclosed

Closing (see previous comment).

comment:3 by anonymous, 18 years ago

Resolution: invalid
Status: closedreopened

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 by Luke Plant, 18 years ago

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 by Luke Plant, 18 years ago

Resolution: fixed
Status: reopenedclosed

(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