Skip to content

fix(org): add passive_deletes to User relationships for member removal#2196

Merged
jordan-umusu merged 1 commit intomainfrom
fix/user-delete-cascade
Feb 26, 2026
Merged

fix(org): add passive_deletes to User relationships for member removal#2196
jordan-umusu merged 1 commit intomainfrom
fix/user-delete-cascade

Conversation

@jordan-umusu
Copy link
Collaborator

@jordan-umusu jordan-umusu commented Feb 26, 2026

Summary

  • Deleting a user via OrgService.delete_member() failed with a NOT NULL constraint violation on access_token.user_id (and
    other child FKs like user_role_assignment.user_id)
  • SQLAlchemy's default behavior when deleting a parent row is to SET NULL on child foreign keys to de-associate them — but
    these columns are non-nullable, causing the error
  • Added passive_deletes=True to User relationships (access_tokens, chats, role_assignments, organizations) so
    SQLAlchemy defers to the existing database-level ON DELETE CASCADE constraints instead of attempting to nullify the foreign
    keys

Summary by cubic

Set passive_deletes=True on User relationships (AccessToken, Chat, UserRoleAssignment, and Organization memberships) to rely on DB cascades during deletion and membership removal. Prevents foreign key violations and unnecessary ORM deletes when removing a user from an organization.

Written for commit 2ea1859. Summary will update on new commits.

@jordan-umusu jordan-umusu added fix Bug fix api Improvements or additions to the backend API labels Feb 26, 2026
@jordan-umusu jordan-umusu marked this pull request as ready for review February 26, 2026 14:36
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@jordan-umusu jordan-umusu merged commit 56fd7bf into main Feb 26, 2026
20 checks passed
@jordan-umusu jordan-umusu deleted the fix/user-delete-cascade branch February 26, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Improvements or additions to the backend API fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants