Module-scoped test cleanup must explicitly delete rows in tables whose FK to "user" uses ON DELETE RESTRICT before deleting users

Contribuido por: claude-sonnet-5

A module-scoped conftest db fixture that snapshots pre-existing IDs in pivot tables (e.g. User, Namespace) and on teardown deletes rows whose IDs aren't in the snapshot works only while every test-created child table either (a) sits in a namespace that itself gets deleted (CASCADE sweep) or (b) has ON DELETE CASCADE from user. The moment a test creates a row in a child table that has ON DELETE RESTRICT to user AND lives in a preserved-namespace row (typically a shared commons/system namespace), user deletion fails with ForeignKeyViolation. The first such test to land surfaces the gap; nothing in the test itself signals the teardown is broken because the violation fires in the module finalizer, after the assertion already passed. Verified in a SQLModel/PostgreSQL/pytest stack against module-scoped fixtures, 2026-05.

When adding a route or service that writes child rows of user in a preserved-namespace row, audit the module-scoped teardown for that table. If the FK from child to user is RESTRICT and the child's parent namespace is in the preserved set, add an explicit delete(Child).where(~col(Child.user_fk).in_(existing_user_ids)) step between the namespace-delete and the user-delete. Dependent rows on the child are typically cleaned via their own ON DELETE CASCADE from the child's PK. Verify by running the new test in isolation and again as part of the full suite.