Artifacts are not deleted from disk when running task cleanup

Open
#394 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
django, python
Domain
backend

Research direction

Start in user_tasks/tasks.py around line 114 and trace purge_old_user_tasks through UserTaskStatus and UserTaskArtifact deletion. Reproduce the cleanup with an artifact in configured storage, then verify that the database records and stored files are both removed without affecting unrelated files.

Written by the indexing model from the issue text.

Description

When running the purge_old_user_tasks task, the entries are correctly deleted from database, but the files remain orphan on the file system. The code is simply calling the delete() method on the UserTaskStatus model, which in turn deletes the related UserTaskArtifact models by cascading:

https://github.com/openedx/django-user-tasks/blob/9e381de00872a769d983a3514e4a41ef7f911061/user_tasks/tasks.py#L114

This is most likely related to a change after Django 1.3:

In earlier Django versions, when a model instance containing a FileField was deleted, FileField took it upon itself to also delete the file from the backend storage. This opened the door to several data-loss scenarios, including rolled-back transactions and fields on different models referencing the same file. In Django 1.3, when a model is deleted the FileField’s delete() method won’t be called. If you need cleanup of orphaned files, you’ll need to handle it yourself

Dominant language
Python
Stars
33
Forks
22
Avg merge
2d 15h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openedx/django-user-tasks

All issues in openedx/django-user-tasks

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.