Channel deletion cascades away sent_alerts history that the DB was designed to keep #48
Labels
No labels
area:ai
area:ci-cd
area:notifications
area:observability
area:public-pages
backlog
bug
duplicate
enhancement
help wanted
invalid
question
type:decision
type:feature
type:infra
type:maintenance
type:security
v1.0.1
v1.1.0
v1.2.0
v1.3.0
v2.0.0
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rbrooks/WeatherBot#48
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
NotificationChannel.sent_alertsdeclarescascade="all, delete-orphan"(app/models/channel.py:41-43) while the FK is
ondelete="SET NULL"(app/models/alert.py:20-22, migration 0001:72) — the documented design is that
channel deletion leaves history as dashboard-only rows. The ORM cascade wins on
await db.delete(ch)(app/api/channels.py:143) and hard-deletes everyassociated
SentAlert. Remove the delete cascade and addpassive_deletes=Trueso the DB behavior applies; add a regression test thatdeletes a channel and asserts its
SentAlertrows persist withchannel_id IS NULL. Note the SQLite test double doesn't enforce FK behavioridentically — assert via ORM state, or cover in the Postgres tier (F-29).
Acceptance criteria:
Filed from the 2026-07-17 codebase audit (
docs/.internal/report-2026-07-17.md), finding F-09.Fixed in #92 (merged to
main). Droppedcascade="all, delete-orphan"onNotificationChannel.sent_alertsand setpassive_deletes=True, so channel deletion defers to the DB'sON DELETE SET NULLand preserves history as dashboard-only rows. Regression test asserts the rows are not cascade-deleted (fullchannel_id IS NULLsemantics are authoritative on the Postgres tier — SQLite doesn't enforce FKs here).