un1t/django-cleanup

Doesn't seem to work with replaced files under Django 2.0.3

Closed this issue · 3 comments

I'm trying it out for the first time, and noticed that while it does correctly delete the files when the model instance is deleted, it fails to delete files when they are replaced.

Hooking it up to a debugger and stepping through the code, it appears that in 'django_cleanup.handlers.delete_old_post_save, fetching the cached FileFieldreturns *the same object* as the "new"FileField. My suspicion is that in the past Django would create a new File` object when a file is replaced, but the current version instead updates the existing object. I suspect that the solution is to have the cache system store a copy of the field.

I'm going to run some experiments and report back.

I'm starting to think that this might be something funky Wagtail is doing. It seems like its admin might be creating new model instances, copying the data over (including the pk) then saving. So there'd be no opportunity for django_cleanup to set the caching attribute on the model instance.

Looking into using Django's caching framework, which should solve the issue.

*sigh* Confirmed. So, basically, it's because of Wagtail serializing/deserializing existing instances before saving. Ugh.

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.