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

PermissionError: There was an exception deleting the file because it is being used by another process #84

Closed ggmblr closed 3 years ago

ggmblr commented 3 years ago

Strange kind of bug i came across.

When initiating a model instance, and then opening it in the admin page as if i were to modify it, simpli saving without making any changes prompts me with the following traceback:

There was an exception deleting the file `logo/6000_4000.webp` on field `accounts.restaurant.logo`
Traceback (most recent call last):

  File "C:\Users\sherzog\web_app\env\lib\site-packages\django_cleanup\handlers.py", line 96, in run_on_commit
    file_.delete(save=False)

  File "C:\Users\sherzog\web_app\env\lib\site-packages\django\db\models\fields\files.py", line 373, in delete
    super().delete(save)

  File "C:\Users\sherzog\web_app\env\lib\site-packages\django\db\models\fields\files.py", line 105, in delete
    self.storage.delete(self.name)

  File "C:\Users\sherzog\web_app\env\lib\site-packages\django\core\files\storage.py", line 304, in delete
    os.remove(name)

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\sherzog\\web_app\\backend\\media\\logo\\6000_4000.webp'

It seems it is interpreting this as a replacement of the original logo with the same one, or something like this. Should i be worried about this?

vinnyrose commented 3 years ago

What version of django_cleanup are you using?

ggmblr commented 3 years ago

I'm using django-cleanup==5.1.0

vinnyrose commented 3 years ago

Can you provide a minimal sample model and field? Typically this happens when either the settings MEDIA_ROOT or the field upload_to is misconfigured.

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.