kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Deleted lessons and quizzes never free their content on a learner-only device

Open rtibblesbot opened this issue 2 months ago • 1 comments

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

Target branch: develop

Observed behavior

On a learner-only device, deleting a lesson leaves its downloaded resources on disk. The lesson disappears from the learner's Home page, but Device > Channels still lists the channel and its size.

The LOD does create a removal request when the IndividualSyncableLesson is deleted, and it never runs. The sync cleanup deletes the LessonAssignment rows and leaves the local Lesson row behind (update_assignments_from_individual_syncable_lessons), so the ContentDownloadRequest rows that row emitted — source model lesson — survive. incomplete_removals_queryset skips a removal whose node still has a download from a different source, and the removal's source is individualsyncablelesson. It stays PENDING on every later import run.

kolibri/core/exams/single_user_assignment_utils.py deletes only the ExamAssignment rows the same way.

Adding the stale row to that to_delete queryset is not enough on its own: the block runs under DisablePostDeleteSignal, which clears every post_delete receiver — including the one that emits the removable assignment.

Device > Channels on the LOD after the lesson was deleted and the device synced

Errors and logs

LOD rows after the deletion sync and the automatic import task:

content_contentrequest
type      status    source_model              count
DOWNLOAD  COMPLETED lesson                    2
REMOVAL   PENDING   individualsyncablelesson  2

lessons_lesson                    1 row, the deleted lesson, is_active=1
lessons_lessonassignment          0 rows
lessons_individualsyncablelesson  0 rows

Expected behavior

Deleting a lesson or a quiz frees its downloaded resources on a learner-only device, the way deleting a course does after #15305.

User-facing consequences

A learner-only device never reclaims the space a lesson or quiz took. Every lesson a coach assigns and later deletes leaves its resources on the device permanently.

Steps to reproduce

  1. Set up a full facility device and a learner-only device for a learner who is a member of a classroom.
  2. As the coach, create a lesson with two resources and assign it to the entire class.
  3. Sign in as the learner on the LOD to sync. Device > Channels lists the channel.
  4. As the coach, delete the lesson.
  5. Sign in as the learner on the LOD again to sync, and wait for the automatic import task.
  6. The lesson is gone from Home; Device > Channels still lists the channel.

Context

  • Kolibri 0.20.0a2.dev280 (develop at 797b9ae7c9).
  • Two local instances on Fedora 44, Chromium via Playwright: full facility device on :8451, LOD on :8452.

Acceptance Criteria

  • [ ] After a lesson is deleted and the LOD syncs, the lesson's downloaded resources are gone and Device > Channels drops the channel when nothing else holds it.
  • [ ] The same holds for a deleted quiz.
  • [ ] No ContentRemovalRequest is left PENDING once the import task has run after that sync.
  • [ ] The lesson or quiz is untouched on the full facility device after the LOD's cleanup — the local deletion is not pushed back upstream.

AI usage

Found by Claude Code while running two-device QA for #15305, which fixes the course half of #15187. It reproduced the case on the two instances above and drafted this issue.

rtibblesbot avatar Sep 20 '26 04:09 rtibblesbot

Plan: When a lesson or quiz stops being assigned on a SoUD, its downloaded resources become removable and the next import run deletes them.

  • [ ] Deactivate a lesson's ghost row once it has no assignment
  • [ ] Deactivate a quiz's ghost row once it has no assignment
  • [ ] Self-review the produced code

Assumptions — the issue did not settle these; say so if one is wrong.

  • Ghost lessons are deactivated like quizzes, not deleted; deleting them means requesting the removal by hand, since DisablePostDeleteSignal mutes its receiver.
  • Ghosts stranded before this fix keep their content; freeing them means sweeping every active ghost with no assignment on each cleanup.
  • A ghost whose assignment cascaded with a deleted group keeps its content; the same sweep would free it.
  • A learner dropped from the assigned group or classroom keeps the ghost's content: the synced Membership deletion (kolibri/core/auth/models.py:1476-1477) takes that assignment out of the membership-scoped to_delete. Courses do free it (kolibri/core/courses/models.py:142).

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar Sep 22 '26 22:09 rtibblesbot