Opened 16 years ago

Closed 16 years ago

#7658 closed (fixed)

Streaming file uploads fail on Windows XP

Reported by: justin.driscoll@… Owned by: Michael Axiak
Component: Core (Other) Version: dev
Severity: Keywords: 2070-fix
Cc: prigun@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

When you attempt to upload a file larger than the memory cutoff it returns a WindowsError when it attempts to delete the temporary file which still has a handle from the python process because it is not being closed.

Attachments (4)

file_upload_patch.patch (372 bytes ) - added by justin.driscoll@… 16 years ago.
Adds a "close" method to TemporaryUploadedFile.
tempfile.diff (2.9 KB ) - added by Michael Axiak 16 years ago.
New temp module for Windows support
tempfile.2.diff (1.0 KB ) - added by Michael Axiak 16 years ago.
Updated tempfile diff to fix AttributeError problem.
tempfile.3.diff (3.0 KB ) - added by Michael Axiak 16 years ago.
Updated tempfile diff to fix AttributeError problem.

Download all attachments as: .zip

Change History (21)

by justin.driscoll@…, 16 years ago

Attachment: file_upload_patch.patch added

Adds a "close" method to TemporaryUploadedFile.

comment:1 by justin.driscoll@…, 16 years ago

Summary: Streaming file uploads fail on Windows XP

I would also ask the relevant devs to consider adding some exception handling to the file_move_safe function so that even if os.remove(old_file_name) fails the application can continue.

try:

os.remove(old_file_name)

except:

# log the error and continue execution

comment:2 by justin.driscoll@…, 16 years ago

Needs tests: set
Summary: Streaming file uploads fail on Windows XP

Last comment reset the summary, etc. Sorry.

comment:3 by Michael Axiak, 16 years ago

Keywords: 2070-fix added
Owner: changed from nobody to Michael Axiak
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:4 by Michael Axiak, 16 years ago

This should be fixed as of [7859], can you please confirm this?

comment:5 by justin.driscoll@…, 16 years ago

Just updated to the latest revs for both trunk and newforms-admin (7870). Still get the error above in newforms admin but in trunk I now get a IOError "No such file or directory". Here's a snippet of the traceback where it fails:

File "C:\home\Projects\Django\libs\django-trunk\django\core\files\move.py" in file_move_safe

  1. file_move(old_file_name, new_file_name)

File "C:\Python25\lib\shutil.py" in move

  1. copy2(src,dst)

File "C:\Python25\lib\shutil.py" in copy2

  1. copyfile(src, dst)

File "C:\Python25\lib\shutil.py" in copyfile

  1. fsrc = open(src, 'rb')

comment:6 by Michael Axiak, 16 years ago

So it appears there's a reason not to use tempfile.NamedTemporaryFile() on windows. I'm going to create my own NamedTemporaryFile() function for windows.

by Michael Axiak, 16 years ago

Attachment: tempfile.diff added

New temp module for Windows support

comment:7 by Michael Axiak, 16 years ago

Triage Stage: AcceptedReady for checkin

Someone else should probably look at this, but I think this fixes the problems with Windows.

comment:8 by justin.driscoll@…, 16 years ago

Still getting the IOError on streaming uploads after applying the new patch.

in reply to:  8 comment:9 by Michael Axiak, 16 years ago

Replying to justin.driscoll@gmail.com:

Still getting the IOError on streaming uploads after applying the new patch.

Yeah. That's bug #7675.

by Michael Axiak, 16 years ago

Attachment: tempfile.2.diff added

Updated tempfile diff to fix AttributeError problem.

by Michael Axiak, 16 years ago

Attachment: tempfile.3.diff added

Updated tempfile diff to fix AttributeError problem.

comment:10 by justin.driscoll@…, 16 years ago

Just updated to newforms-admin rev 7888 which from what I can see is inline with trunk and now there appears to be an issue with ImageField and streaming uploads as the PIL check for a valid image fails on streamed file. Should I file this as a new issue?

comment:11 by Alex Gaynor, 16 years ago

Justin, there is already a ticket open for that problem, #7673.

comment:12 by anonymous, 16 years ago

Thanks, I ran a search but didn't find anything. Wanted to ask before I filed a dupe.

comment:13 by Andrii Kurinnyi, 16 years ago

Cc: prigun@… added

It looks like close method for the TemporaryUploadFile deletes file on Linux and Mac systems
(didn't have a chance to test it on FreeBSD yet), see #7683

comment:14 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [8096]) Fixed #7658 -- Added some Windows-specific tempfile handling. The standard
stuff doesn't work with the way Django's file uploading code wants to operate.
Patch from Mike Axiak.

comment:15 by justin.driscoll@…, 16 years ago

Resolution: fixed
Status: closedreopened

As of Django r8301 I am still getting a WindowsError when streaming uploads are used:

[Error 32] The process cannot access the file because it is being used by another process: 'c:
docume~1
jdrisc~1
locals~1
temp
eu5ium.upload'

comment:16 by Julien Phalip, 16 years ago

Same issue is reported in #8203.

comment:17 by Julien Phalip, 16 years ago

Resolution: fixed
Status: reopenedclosed

Re-resolving as 'fixed', since the newly reported issue is a *new* one and most likely the same as in #8203. I consider it's a new issue since the problem is now not with the streaming upload, namely, but within the storage phase.

Note: See TracTickets for help on using tickets.
Back to Top