un1t / django-cleanup

Automatically deletes old file for FileField and ImageField. It also deletes files on models instance deletion.
MIT License
1.11k stars 79 forks source link

Data loss if same file is saved in multiple fields #44

Closed singhravi1 closed 5 years ago

singhravi1 commented 5 years ago

If a file is saved in multiple instances, then removing a single instance removes the file and cause 'file not found' error for every other instance.

We need to check if the file is referenced in any other object before deleting.

vinnyrose commented 5 years ago

If I understand what you suggesting, this app would have to load all data in the database and search all of it before deleting any file. Please correct me if I am misunderstanding. But if what I understood is the case then I think this would be firmly a "wontfix".

Multiple instances referencing the same file is not a case that is supported and I would recommend you consider using a file manager app that centralizes references to a file such as django-filer or django-filebrowser or roll your own that supports your use case.

singhravi1 commented 5 years ago

Okay. I understand.

Can you suggest, how can i delete an instance without deleting its associated file?

vinnyrose commented 5 years ago

Will this issue be solved when the “don’t delete default file” feature is merged to master? Or is this a different issue from that?

singhravi1 commented 5 years ago

I dont think so.

Besides, the issue would actually be a 'wontfix' if we have to search every FileField in database before deleting a file.

This case is, i think, not common, that same image would be referenced in multiple models. For this, i have added a setting field which specifies a list of model names for which file should not be deleted. This was the patch for my situation.

vinnyrose commented 5 years ago

resolved with #47

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.