svthalia / concrexit

Thalia Website built on Django.
https://thalia.nu
Other
21 stars 12 forks source link

Thumbnails 'Source' objects are not removed when deleting an album #3441

Closed DeD1rk closed 1 year ago

DeD1rk commented 1 year ago

Describe the bug

Currently when an album is deleted, the Source objects (from django-thumbnails) of its photos aren't deleted. Then, if an album with the same name is uploaded again, we get IntegrityErrors when trying to create photos with the same filenames that already existed.

How to reproduce

  1. Upload album
  2. Delete it
  3. Upload the same album again

Expected behaviour

The Source's are deleted, so there is no integrityerror.

Additional context

https://thalia.sentry.io/issues/4543169553/events/239a90e83abd437e9d7116b45ec30b9a/

This issue would be solved by making photos filenames be uuid's (#3442), and just fixing this single issue won't fix all problems we have with reuploading an album, as there is another problem: Reuploading different photos with the same name does not invalidate the cloudfront cache. So If we do that within 24 hours, facedetection would likely analyze the wrong (stale) cached files, and they would also show up to users. So we also need to either make the filenames unique, or implement cloudfront cache invalidation. Clearly, unique filenames are the easier way to go.

DeD1rk commented 1 year ago

I expect just overriding Album.delete() to call Photo.delete() for all photos (instead of relying on cascade deletion that probably doesn't call Photo.delete()) would fix this. If so, this is easy and fun.