fix(backend): delete an account's Preference row on account deletion (IFC-2867)
Merged
PA
4mo ago+136+136+012345678901234567890123456789-11-11-01234567890123456789
Summary
Follow-up from the user/global preferences work (IFC-2718): a Preference is a StandardNode keyed by a plain-string owner_id, so the schema cannot cascade it with on_delete: cascade when its account is deleted — the row was left behind as unreachable dead data.
This hooks the account-delete mutation to drop the row explicitly (ticket option 1, the cleanup hook). Accounts are branch-agnostic, so the deletion is effective everywhere at once and the hook needs no branch condition.
Changes
PreferenceRepository.delete_for_owner(owner_id)— deletes every Preference row for an owner; no-op when there is none.InfrahubAccountMutation.mutate_delete— after the account delete succeeds, drops the account's Preference row. Best-effort: a cleanup failure logs a warning instead of failing the mutation (the account is already gone, and the orphan stays benign since account ids are UUIDs and never reused).- Updated the
Preferencedocstring, which pointed at IFC-2867 as the tracking ticket. - Changelog fragment.
Tests
- Component (repository):
delete_for_ownerremoves only the target owner's row (other owners + global row untouched); no-op when no row exists. - Component (GraphQL):
CoreAccountDeleteremoves the deleted account's Preference row and leaves the global row untouched. - Ran locally: ruff, mypy, preference unit tests, and both component test files (14 passed).
Jira: IFC-2867
🤖 Generated with Claude Code
Summary by cubic
Deletes an account’s Preference row when the account is deleted to prevent orphaned data. Global preferences stay untouched. (IFC-2867)
- Bug Fixes
- Added
PreferenceRepository.delete_for_owner(owner_id)using a single-queryPreferenceDeleteByOwnerQuery(DETACH DELETEbyowner_id). - Updated
CoreAccountDeleteto run cleanup under the per-owner preference lock; on failure catchDatabaseError,QueryTimeoutError,DriverError,Neo4jError, andRedisError, log, and do not fail. Trimmed comments, removed ticket IDs, and dropped the unreleased changelog fragment.
- Added