Django

Code

Ticket #2045 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

TypeError: string indices must be integers

Reported by: amcnabb@mcnabbs.org Assigned to: adrian
Milestone: Component: Validators
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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"

Attachments

Change History

05/31/06 06:29:30 changed by ubernostrum

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.

05/31/06 09:48:39 changed by adrian

  • status changed from new to closed.
  • resolution set to invalid.

Closing (see previous comment).

05/31/06 22:04:08 changed by anonymous

  • status changed from closed to reopened.
  • resolution deleted.

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.

06/01/06 14:51:46 changed 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.

06/01/06 15:47:36 changed by lukeplant

  • status changed from reopened to closed.
  • resolution set to fixed.

(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.


Add/Change #2045 (TypeError: string indices must be integers)




Change Properties
Action