#27716: FieldFile incorrectly returns bytes the first time it is opened with 'r'
------------------------------------------------+------------------------
               Reporter:  Tom                   |          Owner:  nobody
                   Type:  Bug                   |         Status:  new
              Component:  File uploads/storage  |        Version:  1.10
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  0
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 This is strange. On the latest 1.10 release with Python 3.5.2 if I have
 this model, created in a fresh project with no non-default settings (other
 than 'MEDIA_ROOT' set to a directory and a single app in INSTALLED_APPS
 with this model):


 {{{
 class SomeModel(models.Model):
     fd = models.FileField()
 }}}

 Then I run this in `manage.py shell`:

 {{{
 >>> s = SomeModel.objects.create(fd='test.txt')
 >>> s.fd.size
 5
 >>> s.fd.closed
 True
 >>> s.fd.open('r')
 >>> s.fd.read()
 b'hello'
 >>> s.fd.close()
 >>> s.fd.open('r')
 >>> s.fd.read()
 'hello'
 }}}

 The first time a `FileField` is opened it appears to disregard the
 encoding given and always returns bytes. However the second time it
 correctly returns a string. If you re-fetch the model then the behavior
 happens again.

--
Ticket URL: <https://code.djangoproject.com/ticket/27716>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/046.cc4ccd76c325c3ca50e76c398f357f97%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to