Deleted lessons and quizzes never free their content on a learner-only device
❌ 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.

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
- Set up a full facility device and a learner-only device for a learner who is a member of a classroom.
- As the coach, create a lesson with two resources and assign it to the entire class.
- Sign in as the learner on the LOD to sync.
Device > Channelslists the channel. - As the coach, delete the lesson.
- Sign in as the learner on the LOD again to sync, and wait for the automatic import task.
- The lesson is gone from Home;
Device > Channelsstill lists the channel.
Context
- Kolibri 0.20.0a2.dev280 (
developat 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 > Channelsdrops the channel when nothing else holds it. - [ ] The same holds for a deleted quiz.
- [ ] No
ContentRemovalRequestis leftPENDINGonce 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.
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
DisablePostDeleteSignalmutes 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
Membershipdeletion (kolibri/core/auth/models.py:1476-1477) takes that assignment out of the membership-scopedto_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