openedx / openedx/django-user-tasks

Artifacts are not deleted from disk when running task cleanup

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

Nobody has claimed this yet.

Dominant language
Python
Stars
33
Forks
20
PR merge metrics
No merged PRs in 30d

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

Contributor guide

Open the contributing guide

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.