#21057 closed Bug (fixed)
FileSystemStorage can leave temporary files around
Reported by: | John Hensley | Owned by: | nobody |
---|---|---|---|
Component: | File uploads/storage | Version: | 1.5 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
FileSystemStorage._save doesn't close the file passed in the content argument, unless it has a 'temporary_file_path' attribute. When you upload a file bigger than FILE_UPLOAD_MAX_MEMORY_SIZE via a FileField on a ModelForm, content is its FieldFile, not the underlying NamedTemporaryFile. It doesn't have a temporary_file_path attribute, so is treated like an upload that has to be copied, not moved, and is never explicitly closed.
This is probably OK most of the time, as the NamedTemporaryFile should eventually be automatically closed and deleted. It certainly seems to be handled properly when running under the dev server. However, under uWSGI the temporary files never seem to be removed. I'm not sure yet why this is, but adding an explicit close solves the problem.
A slight improvement might be also having FieldFile pass its underlying file to the storage save() method, as then not only would the temporary file be cleaned up, but it could just be moved instead of copied, saving some work.
Change History (4)
comment:1 by , 11 years ago
Has patch: | set |
---|
comment:2 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Pull request: https://github.com/django/django/pull/1571