move_slide raises unhandled ValueError if the slide was already deleted #15

Closed
opened 2026-07-28 21:50:47 +00:00 by paulloth1 · 1 comment
paulloth1 commented 2026-07-28 21:50:47 +00:00 (Migrated from github.com)

Problem

`db.move_slide()` does:

```python
slides = await list_slides()
ids = [s["id"] for s in slides]
idx = ids.index(slide_id)
```

If `slide_id` no longer exists (e.g. deleted by someone else between page load and clicking "Up"/"Down" — plausible given the admin UI is intentionally open to multiple concurrent users), `list.index()` raises `ValueError: ... is not in list`, uncaught, producing a raw 500 from `POST /admin/slides/{slide_id}/move`.

Suggested fix

Guard with something like `if slide_id not in ids: return` before calling `.index()`, mirroring the "slide not found → no-op" behavior already used elsewhere (e.g. `toggle_slide`/`delete_slide` are naturally no-ops on a missing id since they're plain `UPDATE`/`DELETE` statements).

## Problem \`db.move_slide()\` does: \`\`\`python slides = await list_slides() ids = [s["id"] for s in slides] idx = ids.index(slide_id) \`\`\` If \`slide_id\` no longer exists (e.g. deleted by someone else between page load and clicking "Up"/"Down" — plausible given the admin UI is intentionally open to multiple concurrent users), \`list.index()\` raises \`ValueError: ... is not in list\`, uncaught, producing a raw 500 from \`POST /admin/slides/{slide_id}/move\`. ## Suggested fix Guard with something like \`if slide_id not in ids: return\` before calling \`.index()\`, mirroring the "slide not found → no-op" behavior already used elsewhere (e.g. \`toggle_slide\`/\`delete_slide\` are naturally no-ops on a missing id since they're plain \`UPDATE\`/\`DELETE\` statements).
paulloth1 commented 2026-07-28 21:52:44 +00:00 (Migrated from github.com)

Fixed in 0bcc65e: move_slide now checks slide_id in ids before calling .index(), no-oping instead of raising if the slide was already deleted. Verified live: POST .../slides/99999/move now returns the normal 303 redirect instead of a 500.

Fixed in 0bcc65e: move_slide now checks slide_id in ids before calling .index(), no-oping instead of raising if the slide was already deleted. Verified live: POST .../slides/99999/move now returns the normal 303 redirect instead of a 500.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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
paul_loth/krautspaceTV#15
No description provided.