#8421: FileField traps error when uploading non-ascii filename
---------------------------------+------------------------------------------
          Reporter:  mizutori    |         Owner:  nobody                
            Status:  new         |     Milestone:  1.0                   
         Component:  Forms       |       Version:  1.0-beta-1            
        Resolution:              |      Keywords:  FileField upload files
             Stage:  Unreviewed  |     Has_patch:  0                     
        Needs_docs:  0           |   Needs_tests:  0                     
Needs_better_patch:  0           |  
---------------------------------+------------------------------------------
Comment (by mizutori):

 A workaround for this problem

 The UnicodeEncodeError is caused by printing an exception message that
 the field key of empty FileInput field is not found in request.FILES;
 {{{
 ---[ in django/utils/datastructures.py ]---
 class MultiValueDict(dict):
   def __getitem__(self, key):
     try:
       list_ = super(MultiValueDict, self).__getitem__(key)
     except KeyError:
       raise MultiValueDictKeyError, "Key %r not found in %r" % (key, self)
 ---
 }}}
 where the self contains request.FILES, whose one filed is empty and other
 field is filled by non-ascii filename.

 When is_valid() is invoked, the KeyError exception is raised by the empty
 field and printing the whole contents of request.FILES. If other field
 is filled by non-ascii filename, printing message occurs
 UnicodeEncodeError.

 My idea to fix this problem is to apply one of these workarounds:

 {{{
 WORKAROUND (candidate 1):
 in django/utils/datastructures.py, suppress exception message like this.

   raise MultiValueDictKeyError, "Key %r not found in %r" % (key, self)
 -->
   raise MultiValueDictKeyError, "Key %r not found" % (key,)
 }}}

 {{{
 WORKAROUND (candidate 2):
 in django/forms/widgets.py, make FileInput widget clever not to dig empty
 field

 class FileInput(Input):
   def value_from_datadict(self, data, files, name):
 #   return files.get(name, None)
     if name in files:
       val = files.get(name)
     else:
       val = None
     return val
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8421#comment:2>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to