#2045 closed defect (fixed)
TypeError: string indices must be integers
Reported by: | 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.
- class FileUploadField(FormField):
- def init(self, field_name, is_required=False, validator_list=[]):
- self.field_name, self.is_required = field_name, is_required
- self.validator_list = [self.isNonEmptyFile] + validator_list 642.
- def isNonEmptyFile(self, field_data, all_data):
- if not field_datacontent: ...
- raise validators.CriticalValidationError, gettext("The submitted file is empty.") 646.
- def render(self, data):
- return '<input type="file" id="%s" class="v%s" name="%s" />' % \
- (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 , 18 years ago
comment:2 by , 18 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Closing (see previous comment).
comment:3 by , 18 years ago
Resolution: | invalid |
---|---|
Status: | closed → 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 by , 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 , 18 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
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.