#13809: FileField open method is only accepting 'rb' modes
--------------------------------------+------------------------------------
     Reporter:  canassa               |                    Owner:  nobody
         Type:  Bug                   |                   Status:  reopened
    Component:  File uploads/storage  |                  Version:  SVN
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  1                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by davidfstr):

 * cc: davidfstr (added)


Comment:

 I confirm this issue as still present in Django 1.3.

 In short, if you call {{{FieldFile.open(mode=NOT_RB)}}}, it will always
 open in mode {{{rb}}}. This is due to {{{FieldFile.open}}} calling the
 {{{self.file}}} property, which auto-opens in 'rb' mode.
 {{{FieldFile.open}}} attempts to subsequently call {{{open}}} on this new
 file, but that does not reopen the file again.

 My suggested workaround for:
 * {{{field_file.open(mode='w+b')}}}
 is:
 * {{{field_file.file = field_file.storage.open(field_file.name, 'w+b')}}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/13809#comment:7>
Django <https://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