Garbage collection never deletes orphaned files from storage

Open
#6,447 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

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

Research direction

Read contentcuration/contentcuration/utils/garbage_collect.py and the named tests in contentcuration/contentcuration/tests/utils/test_garbage_collect.py; start by running the focused pytest command from the issue. The issue says contributions are not open for this task, so it is not suitable for a first contribution.

Written by the indexing model from the issue text.

Description

bug DEV: backend

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: unstable

Observed behavior

_clean_up_files assigns a Django Exists(...) expression to is_other_node_pointing and tests if not is_other_node_pointing:. The expression is never run as a query, and an Exists object is always truthy, so default_storage.delete is never called. manage.py garbage_collect deletes the File rows of orphaned nodes and leaves their storage objects in the bucket.

User-facing consequences

Storage objects of garbage-collected content are never reclaimed, so the bucket only grows.

Steps to reproduce

  1. In test_deletes_associated_files, add assert not default_storage.exists("storage/a/a/aaa.jpg") after clean_up_contentnodes().
  2. Run pytest contentcuration/contentcuration/tests/utils/test_garbage_collect.py -k test_deletes_associated_files.
  3. The new assertion fails: the object is still stored.

Acceptance Criteria

  • After clean_up_contentnodes(), a storage object referenced only by File rows of the cleaned-up nodes no longer exists in default_storage.
  • A storage object also referenced by a File row outside the cleaned-up nodes still exists.
  • clean_up_contentnodes() completes when a File row's storage object is already absent: GoogleCloudStorage.delete raises AttributeError for a missing object.

AI usage

Claude Code (Fable 5.2) found this while planning #6445 and wrote the issue.

Dominant language
JavaScript
Stars
214
Forks
327
Avg merge
17h 5m
Merged PRs (30d)
25

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 learningequality/studio

All issues in learningequality/studio

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.