Opened 7 years ago
Last modified 17 months ago
#29510 closed Bug
QueryDict.copy() returns closed files when the type of file is TemporaryUploadedFile — at Version 2
| Reported by: | Liquid Scorpio | Owned by: | nobody |
|---|---|---|---|
| Component: | File uploads/storage | Version: | 1.11 |
| Severity: | Normal | Keywords: | QueryDict, upload, file |
| Cc: | Jeff, Herbert Fortes, Dmytro Litvinov | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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]:
Change History (2)
comment:1 by , 7 years ago
| Component: | Uncategorized → File uploads/storage |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 7 years ago
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.
I can reproduce with Python 2, even if I'm unsure that the behavior is incorrect:
>>> from django.core.files.uploadedfile import TemporaryUploadedFile >>> from copy import deepcopy >>> f = TemporaryUploadedFile('test.jpg', 'image/jpeg', 100, 'utf-8') f.seekable() True a = deepcopy(f) >>> a.seekable() FalseHowever, the
deepcopy()crashes on Python 3 with:TypeError: cannot serialize '_io.BufferedRandom' objectAccepting for further investigation.