#29510: QueryDict.copy() returns closed files when the type of file is
TemporaryUploadedFile
-------------------------------------+-------------------------------------
     Reporter:  Liquid Scorpio       |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  File                 |                  Version:  1.11
  uploads/storage                    |
     Severity:  Normal               |               Resolution:
     Keywords:  QueryDict, upload,   |             Triage Stage:  Accepted
  file                               |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Liquid Scorpio:

Old description:

> When uploaded file size is greater than `FILE_UPLOAD_MAX_MEMORY_SIZE`,
> Django uses `TemporaryUploadedFile` to represent the file object.
> However, when executing `.copy()` on a `QueryDict` containing such a
> file, the returned object has the file but it is in closed state
> (`seekable()` is `False`).
>
> **Expected**: File should present in open state (`seekable()` should be
> `True`)
>
> Below is a reproducible example and also contains version details:
>
> {{{
> Python 2.7.12 (default, Dec  4 2017, 14:50:18)
> In [18]: import django
>
> In [19]: django.VERSION
> Out[19]: (1, 11, 11, u'final', 0)
>
> In [20]: from django.http.request import QueryDict
>
> In [21]: from django.core.files.uploadedfile import TemporaryUploadedFile
>
> In [22]: d = QueryDict(mutable=True)
>
> In [23]: f = TemporaryUploadedFile('test.jpg', 'image/jpeg', 100,
> 'utf-8')
>
> In [24]: f.seekable()
> Out[24]: True
>
> In [25]: d.appendlist('image', f)
>
> In [26]: d['image'].seekable()
> Out[25]: True
>
> In [27]: c = d.copy()
>
> In [28]: c['image'].seekable()
> Out[28]: False
>
> In [30]:
>
> }}}

New description:

 When uploaded file size is greater than `FILE_UPLOAD_MAX_MEMORY_SIZE`,
 Django uses `TemporaryUploadedFile` to represent the file object. However,
 when executing `.copy()` on a `QueryDict` containing such a file, the
 returned object has the file but it is in closed state (`seekable()` is
 `False`).

 **Expected**: File should be present in open state (`seekable()` should be
 `True`)

 Below is a reproducible example and also contains version details:

 {{{
 Python 2.7.12 (default, Dec  4 2017, 14:50:18)
 In [18]: import django

 In [19]: django.VERSION
 Out[19]: (1, 11, 11, u'final', 0)

 In [20]: from django.http.request import QueryDict

 In [21]: from django.core.files.uploadedfile import TemporaryUploadedFile

 In [22]: d = QueryDict(mutable=True)

 In [23]: f = TemporaryUploadedFile('test.jpg', 'image/jpeg', 100, 'utf-8')

 In [24]: f.seekable()
 Out[24]: True

 In [25]: d.appendlist('image', f)

 In [26]: d['image'].seekable()
 Out[25]: True

 In [27]: c = d.copy()

 In [28]: c['image'].seekable()
 Out[28]: False

 In [30]:

 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29510#comment:2>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.be3d481a912caeae725f504056cd20aa%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to