mirror of
https://github.com/django/django.git
synced 2025-10-09 18:12:39 +00:00
[1.7.x] Fixed #22680 -- I/O operation on closed file.
This patch is two-fold; first it ensure that Django does close everything in
request.FILES at the end of the request and secondly the storage system should
no longer close any files during save, it's up to the caller to handle that --
or let Django close the files at the end of the request.
Backport of e2efc8965e
from master.
This commit is contained in:
parent
de0e285be8
commit
1ff11304dc
10 changed files with 79 additions and 6 deletions
|
@ -19,7 +19,8 @@ from django.core.cache import cache
|
|||
from django.core.exceptions import SuspiciousOperation
|
||||
from django.core.files.base import File, ContentFile
|
||||
from django.core.files.storage import FileSystemStorage, get_storage_class
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.core.files.uploadedfile import (InMemoryUploadedFile, SimpleUploadedFile,
|
||||
TemporaryUploadedFile)
|
||||
from django.test import LiveServerTestCase, SimpleTestCase
|
||||
from django.test import override_settings
|
||||
from django.utils import six
|
||||
|
@ -206,6 +207,23 @@ class FileStorageTests(unittest.TestCase):
|
|||
|
||||
self.storage.delete('path/to/test.file')
|
||||
|
||||
def test_save_doesnt_close(self):
|
||||
with TemporaryUploadedFile('test', 'text/plain', 1, 'utf8') as file:
|
||||
file.write(b'1')
|
||||
file.seek(0)
|
||||
self.assertFalse(file.closed)
|
||||
self.storage.save('path/to/test.file', file)
|
||||
self.assertFalse(file.closed)
|
||||
self.assertFalse(file.file.closed)
|
||||
|
||||
file = InMemoryUploadedFile(six.StringIO('1'), '', 'test',
|
||||
'text/plain', 1, 'utf8')
|
||||
with file:
|
||||
self.assertFalse(file.closed)
|
||||
self.storage.save('path/to/test.file', file)
|
||||
self.assertFalse(file.closed)
|
||||
self.assertFalse(file.file.closed)
|
||||
|
||||
def test_file_path(self):
|
||||
"""
|
||||
File storage returns the full path of a file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue