Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#31201 closed Bug (wontfix)

Atomic Transaction Roll Back File Upload

Reported by: Yash Jhunjhunwala Owned by: nobody
Component: File uploads/storage Version: 2.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

For a Model A with FileField

Model A(models.Model)
 file_field = models.FileField()

Save an instance of model A under a transaction block,
If the transaction fails i.e not committed/rollback , the uploaded file is not deleted, even though the instance of the model is not saved

Change History (2)

comment:1 by Carlton Gibson, 5 years ago

Resolution: wontfix
Status: newclosed

This is long-standing behavior, I'm afraid.

FileField docs:

Note that when a model is deleted, related files are not deleted. If you need to cleanup orphaned files, you’ll need to handle it yourself (for instance, with a custom management command that can be run manually or scheduled to run periodically via e.g. cron).

c.f. Malcolm Tredinnick on https://code.djangoproject.com/ticket/11663#comment:14

For me, just quickly trying to think about how one might tie the transaction rollback into the file upload handling, a periodic cleanup command is instantly more appealing. I hope that makes sense.

Last edited 5 years ago by Carlton Gibson (previous) (diff)

comment:2 by Carlton Gibson, 5 years ago

Component: UncategorizedFile uploads/storage
Note: See TracTickets for help on using tickets.
Back to Top