un1t/django-cleanup

If two instances refer to the same file, deleting on of them causing file deletion

Closed this issue · 2 comments

If two instances have the same ImageField, deleting on of them causing file deletion.

This seems within defined behavior for this app. I understand it is not ideal, but this type of expected behavior is more so a storage level concern or application design concern.

We look at per-instance changes of "strings". We don't actually look at "files" per se, just the "string" that somehow represents that file. When the conditions are right we tell the "string" to delete itself, how that command is interpreted is up to the storage class for that ImageField.

I would recommend one (or more) of:
Don't allow fields to reference the same file (database unique constraint?).
Rename files on upload if a conflict exists, or random file names.
If you need the same file often add a level of indirection to the same file using one of the media management plugins: https://djangopackages.org/grids/g/file-managers/
Looking for or make a custom storage backend to track file duplicates:
https://docs.djangoproject.com/en/dev/howto/custom-file-storage/
https://djangopackages.org/grids/g/storage-backends/

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.