Django

Code

Ticket #6456 (new)

Opened 5 months ago

Last modified 4 months ago

FileField deletes files even when model instance is deleted in a transaction that is rolled back

Reported by: durdinator Assigned to: nobody
Milestone: Component: Core framework
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I've got a model with a few FileFields?. I've got code resembling this:

class SomeObject(models.Model):
    ...

class RelatedFile(models.Model):
    filename = models.FileField(...)
    owner = models.ForeignKey(SomeObject, related_name='related_files')

@commit_on_success
def update_files(request, id):
    obj = get_object_or_404(SomeObject, pk=id)
    obj.related_files.all().delete()
    ... more code - which depending on external conditions can raise an exception ...

Since the FileField? hooks the RelatedFile?'s post_delete signal, it deletes the original files when the delete() method is called. Then if the transaction is rolled back, the rows in the database, not being deleted after all, point to nonexistent files.

Attachments

Change History

03/18/08 20:18:44 changed by PhiR

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

right now there's no signal for commit/rollback, and I guess we'd need that to make sure the files aren't deleted yet. See #5415 for the implementation of something similar.


Add/Change #6456 (FileField deletes files even when model instance is deleted in a transaction that is rolled back)




Change Properties
Action