From 1ff11304dcebbabdede8ef3d659ca0e54055e2fd Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Sun, 25 May 2014 22:52:47 +0200 Subject: [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 e2efc8965edf684aaf48621680ef54b84e116576 from master. --- django/http/request.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'django/http/request.py') diff --git a/django/http/request.py b/django/http/request.py index ded4744a87..ecad639c82 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -5,6 +5,7 @@ import os import re import sys from io import BytesIO +from itertools import chain from pprint import pformat from django.conf import settings @@ -245,6 +246,11 @@ class HttpRequest(object): else: self._post, self._files = QueryDict('', encoding=self._encoding), MultiValueDict() + def close(self): + if hasattr(self, '_files'): + for f in chain.from_iterable(l[1] for l in self._files.lists()): + f.close() + # File-like and iterator interface. # # Expects self._stream to be set to an appropriate source of bytes by -- cgit v1.3