Skip to content

Fix admin user deletion cascading - #4

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-bd0e
Draft

Fix admin user deletion cascading#4
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-bd0e

Conversation

@cursor

@cursor cursor Bot commented Jun 18, 2026

Copy link
Copy Markdown

Bug and impact

Admin user deletion relied on database-level ON DELETE CASCADE for most user-owned tables. The default SQLite engine does not enable foreign-key cascades, so deleting a user could leave private reports, report views, chats, API keys, schedules, and token ledger rows orphaned after the account row was removed.

Root cause

delete_user only called db.delete(user), while the User ORM model only cascades subscriptions and profile relationships. Other dependencies are modeled only with database foreign keys.

Fix

Explicitly delete user-owned dependent records in dependency order before deleting the user row, with rollback on failure.

Validation

  • python3 -m unittest backend.tests.test_admin_service
  • git diff --check HEAD~1..HEAD
Open in Web View Automation 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant