#29510: QueryDict.copy() returns closed files when the type of file is
TemporaryUploadedFile
-------------------------------------+-------------------------------------
Reporter: Liquid Scorpio | Owner: Dan
| Madere
Type: Bug | Status: assigned
Component: File | Version: 1.11
uploads/storage |
Severity: Normal | Resolution:
Keywords: QueryDict, upload, | Triage Stage: Accepted
file |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Carlton Gibson):
Hey Dan. Sorry for the pause. Getting there now.
Can I ask you to clarify this:
> Not necessarily, it could also be making a copy of request.POST, which
surprisingly includes the files too.
I'm looking at `% ./runtests.py file_uploads -k test_simple_upload
--parallel=1` and `% ./runtests.py file_uploads -k test_large_upload
--parallel=1` and inspecting the request for the views:
{{{
(django) carlton@Carltons-MacBook-Pro tests % ./runtests.py file_uploads
-k test_simple_upload --parallel=1
Testing against Django installed in
'/Users/carlton/Projects/Django/django/django'
Found 1 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
<WSGIRequest: POST '/upload/'>
POST:
<QueryDict: {'name': ['Ringo']}>
FILES:
<MultiValueDict: {'file_field': [<InMemoryUploadedFile: tests.py
(text/x-python)>]}>
>
/Users/carlton/Projects/Django/django/tests/file_uploads/views.py(31)file_upload_view()
-> form_data = request.POST.copy()
(Pdb) interact
*interactive*
>>> request.POST.copy()
<QueryDict: {'name': ['Ringo']}>
>>> request.FILES.copy()
<MultiValueDict: {'file_field': [<InMemoryUploadedFile: tests.py
(text/x-python)>]}>
>>> request.FILES.copy()["file_field"]
<InMemoryUploadedFile: tests.py (text/x-python)>
>>> request.FILES.copy()["file_field"].seekable()
True
}}}
And the same here:
{{{
(django) carlton@Carltons-MacBook-Pro tests % ./runtests.py file_uploads
-k test_large_upload --parallel=1
Testing against Django installed in
'/Users/carlton/Projects/Django/django/django'
Found 1 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
<WSGIRequest: POST '/verify/'>
POST:
<QueryDict: {'name': ['Ringo'], 'name_hash':
['a6d6d397a391d876d5aae28cdca9f25071906022'], 'file_field1_hash':
['b84b7b775430232c2ee4e2216db1a591d97b2db0'], 'file_field2_hash':
['fbcf384f1c96e3d24fb25b749b00241a5cc4690f']}>
FILES:
<MultiValueDict: {'file_field1': [<TemporaryUploadedFile:
tmpx56phiic.file1 (application/octet-stream)>], 'file_field2':
[<TemporaryUploadedFile: tmp7ipmyal8.file2 (application/octet-stream)>]}>
>
/Users/carlton/Projects/Django/django/tests/file_uploads/views.py(59)file_upload_view_verify()
-> form_data = request.POST.copy()
(Pdb) interact
*interactive*
>>> request.POST.copy()
<QueryDict: {'name': ['Ringo'], 'name_hash':
['a6d6d397a391d876d5aae28cdca9f25071906022'], 'file_field1_hash':
['b84b7b775430232c2ee4e2216db1a591d97b2db0'], 'file_field2_hash':
['fbcf384f1c96e3d24fb25b749b00241a5cc4690f']}>
>>> request.FILES.copy()
<MultiValueDict: {'file_field1': [<TemporaryUploadedFile:
tmpx56phiic.file1 (application/octet-stream)>], 'file_field2':
[<TemporaryUploadedFile: tmp7ipmyal8.file2 (application/octet-stream)>]}>
>>> request.FILES.copy()["file_field1"]
<TemporaryUploadedFile: tmpx56phiic.file1 (application/octet-stream)>
>>> request.FILES.copy()["file_field1"].seekable()
True
}}}
So, it's neither the case that `request.POST` includes the files data nor
that copying `request.FILES` leads to the error. 🤔
I do get the error creating the `TemporaryUploadedFile` by-hand, so I need
to see what's different about the upload flow.
If you were able to provide a (minimal but) full reproduce, it might save
a cycle.
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/29510#comment:18>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070185c9a9fb58-c67cf4c0-094b-48fc-89bb-7d81c85d21a9-000000%40eu-central-1.amazonses.com.