mirror of
https://github.com/django/django.git
synced 2025-11-01 20:31:40 +00:00
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.
This commit is contained in:
parent
a1c6cd6a16
commit
e2efc8965e
10 changed files with 79 additions and 6 deletions
|
|
@ -327,6 +327,37 @@ class FileUploadTests(TestCase):
|
|||
self.assertEqual(got.get('file1'), 1)
|
||||
self.assertEqual(got.get('file2'), 2)
|
||||
|
||||
def test_fileuploads_closed_at_request_end(self):
|
||||
file = tempfile.NamedTemporaryFile
|
||||
with file() as f1, file() as f2a, file() as f2b:
|
||||
response = self.client.post('/fd_closing/t/', {
|
||||
'file': f1,
|
||||
'file2': (f2a, f2b),
|
||||
})
|
||||
|
||||
request = response.wsgi_request
|
||||
# Check that the files got actually parsed.
|
||||
self.assertTrue(hasattr(request, '_files'))
|
||||
|
||||
file = request._files['file']
|
||||
self.assertTrue(file.closed)
|
||||
|
||||
files = request._files.getlist('file2')
|
||||
self.assertTrue(files[0].closed)
|
||||
self.assertTrue(files[1].closed)
|
||||
|
||||
def test_no_parsing_triggered_by_fd_closing(self):
|
||||
file = tempfile.NamedTemporaryFile
|
||||
with file() as f1, file() as f2a, file() as f2b:
|
||||
response = self.client.post('/fd_closing/f/', {
|
||||
'file': f1,
|
||||
'file2': (f2a, f2b),
|
||||
})
|
||||
|
||||
request = response.wsgi_request
|
||||
# Check that the fd closing logic doesn't trigger parsing of the stream
|
||||
self.assertFalse(hasattr(request, '_files'))
|
||||
|
||||
def test_file_error_blocking(self):
|
||||
"""
|
||||
The server should not block when there are upload errors (bug #8622).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue