openedx / openedx/django-user-tasks
Artifacts are not deleted from disk when running task cleanup
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:
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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