Deleting a slot entry / day / routine cascades and permanently deletes workout logs and sessions
Disclaimer: this investigation was done jointly by a human and an AI assistant (the human drove the mobile app and reviewed every step; the AI read the source, ran the API reproduction and verified server state). The text of this issue was written by the AI and reviewed by the human before filing.
Priority/Impact
High (critical issue, blocks workflow) — silent, irreversible loss of training history through routine edits the UI presents as harmless.
Description
Deleting a slot entry, day, slot or routine permanently deletes the workout logs (and, for routines, the sessions) that reference them. There is no warning, and the docs describe logs as independent records that survive routine changes.
WorkoutLog and WorkoutSession back-link to the routine structure with on_delete=CASCADE even though those FKs are nullable:
| Model / field | on_delete |
null |
Source (72dca12) |
|---|---|---|---|
WorkoutLog.routine |
CASCADE | True | wger/manager/models/log.py:104-108 |
WorkoutLog.slot_entry |
CASCADE | True | wger/manager/models/log.py:111-114 |
WorkoutSession.routine |
CASCADE | True | wger/manager/models/session.py:69-73 |
WorkoutSession.day |
CASCADE | True | wger/manager/models/session.py:76-79 |
No model overrides delete(), no viewset overrides destroy, and the pre_delete handlers in wger/manager/signals.py only reset caches, so DRF's default destroy → Django Collector cascades all the way down to the logs.
This contradicts the documented data model (docs/api/routines.rst, "Sessions and logs"):
A WorkoutLog is one performed set, attached to a session and optionally back-linked to a routine, day, slot entry and iteration. Each log carries both what was actually performed … and the originally prescribed values …, so a log preserves both sides even when the routine later changes.
"Optionally back-linked" and "preserves both sides even when the routine later changes" describe a reference, not ownership. The user-facing consequence is that the most natural way to edit a routine — remove an exercise, add another — erases the history of the removed exercise, and finishing a training block by deleting the routine erases the whole block.
(WorkoutSession → WorkoutLog CASCADE is intentional per the changelog (#156) and not part of this report. WorkoutLog.exercise CASCADE is a related concern for custom exercises but is not nullable and would need a different fix.)
Steps to reproduce
Through the mobile app (Android, Play Store build, current as of 2026-09-13), verified against the server via the REST API after each step:
- Create a routine
zz-cascade-test, add a day, add an exercise (Chest Press). Open gym mode and log one set. Server: routine 3, day 5, slot 23, slot entry 23; one session; oneWorkoutLogwithslot_entry=23,routine=3. Totals: 205 logs / 12 sessions (baseline was 204 / 11). - In the routine editor, tap the trash icon on Chest Press (slot entry).
Server:
GET /api/v2/slot-entry/23/→ 404,GET /api/v2/workoutlog/<id>/→ 404, session → 200 (now empty). Totals: 204 / 12. - Add another exercise, log one set (new session + log created). Totals: 205 / 13.
- Delete the routine
zz-cascade-test. Server: routine → 404, both sessions → 404, the log → 404. Totals: 204 / 11 — exactly the baseline.
Pure API reproduction (same result, no app involved):
POST /api/v2/routine/ {"name":"zz","start":"2026-09-13","end":"2026-09-20"} → 201 (id R)
POST /api/v2/day/ {"routine":R,"name":"d","order":1} → 201 (id D)
POST /api/v2/slot/ {"day":D,"order":1} → 201 (id S)
POST /api/v2/slot-entry/ {"slot":S,"exercise":465,"order":1} → 201 (id E)
POST /api/v2/workoutsession/ {"routine":R,"day":D,"datetime_start":...,"impression":"2"} → 201 (id SES)
POST /api/v2/workoutlog/ {"exercise":465,"routine":R,"session":SES,"slot_entry":E,
"repetitions":5,"weight":20,"iteration":1} → 201 (id L)
DELETE /api/v2/slot-entry/E/ → 204
GET /api/v2/workoutlog/L/ → 404 <-- log deleted with the slot entry
GET /api/v2/workoutsession/SES/ → 200
POST /api/v2/workoutsession/ + /api/v2/workoutlog/ (routine=R, no slot_entry) → 201, 201 (SES2, L2)
DELETE /api/v2/routine/R/ → 204
GET /api/v2/workoutsession/SES2/ → 404 <-- session deleted with the routine
GET /api/v2/workoutlog/L2/ → 404 <-- log deleted with the routine (no slot_entry involved)Expected behaviour
Editing or deleting routine structure should never delete performed sets. Concretely: switch the four nullable FKs above to on_delete=SET_NULL (one migration; the app already handles routine: null sessions — e.g. sessions logged outside a routine). Logs keep their own exercise, session, weight, repetitions and *_target fields, so nothing is lost by detaching them; they simply stop appearing under the deleted routine's /logs/ view and remain visible in the calendar / per-exercise history.
Alternatively, if the cascade is intended, the app and web UI should warn "this will delete N logged sets / M sessions" before deleting a slot entry, slot, day or routine, and the docs should say that routine structure owns the history.
Server version
2.8.0-dev.0, self-hosted via docker compose (wger-project/docker), PostgreSQL, PowerSync enabled.
Mobile app version
Android, 2.1.0
Source: wger-project/wger