Opened 16 months ago

Last modified 7 days ago

#30422 assigned Bug

Temporary files do not get deleted on canceled upload request.

Reported by: drutalj Owned by: Sanskar Jaiswal
Component: File uploads/storage Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by felixxm)

Temporary files do not get deleted when upload (request) is canceled by client (e.g. browser is closed before upload is finished).

Change History (9)

comment:1 Changed 16 months ago by felixxm

Description: modified (diff)
Summary: Temp upload file does not get deleted on canceled upload requestTemporary files do not get deleted on canceled upload request.
Triage Stage: UnreviewedAccepted
Version: 2.2master

Reproduced at ed880d92b50c641c3e7f6e8ce5741085ffe1f8fb with django.core.files.uploadhandler.TemporaryFileUploadHandler.

comment:2 Changed 15 months ago by Mattia Procopio

Owner: changed from nobody to Mattia Procopio
Status: newassigned

comment:3 Changed 15 months ago by Mattia Procopio

I am analysing a bit the code to deal with uploads. I have noticed that file_complete method is never called if upload is interrupted.
Now, since content lenght seems to be unreliable (in my tests is always 0) I am thinking how to solve this issue in a clean way.
One of the option I am thinking about is to add a new flag to TemporaryFileUploadHandler that will be set to True within file_complete and having some cleanup code within upload_complete that will check if the flag is True or False and will delete the incomplete file.
Does this sound right?

comment:4 Changed 6 months ago by Sanskar Jaiswal

Does this have a PR merged? If not can I look into this? I want to get started with contributing to Django for a while now, but I haven't been able to do so. Also, could someone please tell me if this ticket is easy enough for a beginner to resolve?

comment:5 Changed 6 months ago by Carlton Gibson

Hi Sanskar. There's no patch. You can look into Mattia's suggestion to see if it makes sense.

comment:6 Changed 6 months ago by Mattia Procopio

Owner: Mattia Procopio deleted
Status: assignednew

comment:7 Changed 6 months ago by Sanskar Jaiswal

Owner: set to Sanskar Jaiswal
Status: newassigned

comment:8 Changed 6 months ago by Carlton Gibson

Has patch: set
Patch needs improvement: set

comment:9 Changed 7 days ago by Sanskar Jaiswal

All tests run on my machine (macOS) but the CI test on Windows fails because of a PermissionError, due to the temporary file being used by some other process. Is there any possible fix for this on Windows? Or should I just alter my patch to handle such os errors and label this patch as POSIX only?

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