Media: deleting a PDF used by a playlist fails with a generic error #155

Closed
opened 2026-11-13 14:35:14 +00:00 by vivy · 3 comments
Owner

What

Deleting a PDF (or any media) that a playlist still uses fails, and the panel says only "Could not delete that item. Try again."

Cause (read in the code, GRI-1960)

  • DELETE /api/v1/media/{id} answers 409 media_in_use while any playlist item references the document or one of its pages (crates/server/src/media/handlers.rs delete_media, FK from playlist_items.media_id).
  • frontend-web/src/screens/MediaScreen.tsx handleDelete catches every error and shows the same generic text. "Try again" can never succeed, and the user is not told why.

Done when

  • The 409 answer names the playlists that use the item (name + id), for a document including its pages.
  • The panel shows that list and offers: Remove from these playlists and delete (one confirm), or cancel.
  • A test covers: delete of a document used by a playlist as a whole item, and as single pages.
  • Other errors keep a generic message; a 409 never says "try again".

Field feedback from the product owner on GRI-1960.

## What Deleting a PDF (or any media) that a playlist still uses fails, and the panel says only *"Could not delete that item. Try again."* ## Cause (read in the code, GRI-1960) - `DELETE /api/v1/media/{id}` answers **409 `media_in_use`** while any playlist item references the document or one of its pages (`crates/server/src/media/handlers.rs` `delete_media`, FK from `playlist_items.media_id`). - `frontend-web/src/screens/MediaScreen.tsx` `handleDelete` catches every error and shows the same generic text. "Try again" can never succeed, and the user is not told why. ## Done when - The 409 answer names the playlists that use the item (name + id), for a document including its pages. - The panel shows that list and offers: *Remove from these playlists and delete* (one confirm), or cancel. - A test covers: delete of a document used by a playlist as a whole item, and as single pages. - Other errors keep a generic message; a 409 never says "try again". Field feedback from the product owner on GRI-1960.
Member

Backend contract for this fix (implementing both sides myself since the task
was routed whole and no backend partner was assigned; flag here if you'd
rather it shaped differently before merge):

  • DELETE /api/v1/media/{id} keeps its 409 media_in_use on conflict, but
    the body now carries an optional details field — {"playlists": [{"id", "name"}, ...]} — naming every playlist that still references the item,
    directly or through one of its pages. ApiError gained details: Option<serde_json::Value>, skip_serializing_if none, so every other
    endpoint's error body is byte-identical to before.
  • DELETE /api/v1/media/{id}?remove_from_playlists=true removes the
    referencing playlist items and deletes the media in one transaction — the
    panel's "Remove from these playlists and delete" confirm.
  • plan/server/rest-api.md updated (Shape row, and the Media table row).
  • Two new integration tests in media_integration.rs cover a document used
    through a page, and a plain image used directly, each checking the 409
    names the playlist and that remove_from_playlists=true detaches and
    deletes.

Frontend: MediaScreen.tsx now shows the named playlists and offers that one
confirm instead of the generic "Could not delete that item. Try again."

Backend contract for this fix (implementing both sides myself since the task was routed whole and no backend partner was assigned; flag here if you'd rather it shaped differently before merge): - `DELETE /api/v1/media/{id}` keeps its `409 media_in_use` on conflict, but the body now carries an optional `details` field — `{"playlists": [{"id", "name"}, ...]}` — naming every playlist that still references the item, directly or through one of its pages. `ApiError` gained `details: Option<serde_json::Value>`, `skip_serializing_if` none, so every other endpoint's error body is byte-identical to before. - `DELETE /api/v1/media/{id}?remove_from_playlists=true` removes the referencing playlist items and deletes the media in one transaction — the panel's "Remove from these playlists and delete" confirm. - `plan/server/rest-api.md` updated (Shape row, and the Media table row). - Two new integration tests in `media_integration.rs` cover a document used through a page, and a plain image used directly, each checking the 409 names the playlist and that `remove_from_playlists=true` detaches and deletes. Frontend: `MediaScreen.tsx` now shows the named playlists and offers that one confirm instead of the generic "Could not delete that item. Try again."
Author
Owner

PR #163 merged into dev (chief of staff review). One gap, still on this issue: Remove from these playlists and delete removes playlist items but does not push the changed playlists to the screens — delete_media never calls push_current_assignment. Screens keep showing the deleted document until the next playlist edit. Fix: after delete_removing_playlist_refs, push every playlist named in the conflict to its devices, with a test. @prismancer, this is yours, small; then #156.

PR #163 merged into dev (chief of staff review). One gap, still on this issue: **Remove from these playlists and delete** removes playlist items but does not push the changed playlists to the screens — `delete_media` never calls `push_current_assignment`. Screens keep showing the deleted document until the next playlist edit. Fix: after `delete_removing_playlist_refs`, push every playlist named in the conflict to its devices, with a test. @prismancer, this is yours, small; then #156.
vivy closed this issue 2026-11-13 20:41:22 +00:00
Author
Owner

Done: #163 (named blocking playlists) and #167 (push the changed playlist to its devices after remove-and-delete) are both merged into dev.

Done: #163 (named blocking playlists) and #167 (push the changed playlist to its devices after remove-and-delete) are both merged into dev.
Sign in to join this conversation.
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Grimoirix/grimoire-of-digital-signage#155
No description provided.