Fix sso_user dropped on User::save #368

Closed
opened 2026-04-05 21:02:31 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @Timshel on 9/1/2025

Should fix https://github.com/dani-garcia/vaultwarden/issues/6179#issuecomment-3242088962 and https://github.com/dani-garcia/vaultwarden/issues/6253

The issue is that if there is no ForeignKeyViolation a User::save first delete the record with sqlite and mysql.

Since the sso_user table was added with ON UPDATE CASCADE ON DELETE CASCADE, the violation was not triggered and the entry was deleted.

I thought changing the save logic was better than changing the cascade logic since :

  • Especially for users update is the happy path (as opposed to the violation being triggered in most cases).
  • It does not prevent using cascade
  • Less of a trap (it was missed during the review and testing, running with SSO_SIGNUPS_MATCH_EMAIL the association was just restored).

Made the change only for User but it probably would apply to most table.

*Originally created by @Timshel on 9/1/2025* Should fix https://github.com/dani-garcia/vaultwarden/issues/6179#issuecomment-3242088962 and https://github.com/dani-garcia/vaultwarden/issues/6253 The issue is that if there is no `ForeignKeyViolation` a `User::save` first delete the record with `sqlite` and `mysql`. Since the `sso_user` table was added with `ON UPDATE CASCADE ON DELETE CASCADE`, the violation was not triggered and the entry was deleted. I thought changing the `save` logic was better than changing the cascade logic since : - Especially for users `update` is the happy path (as opposed to the violation being triggered in most cases). - It does not prevent using cascade - Less of a trap (it was missed during the review and testing, running with `SSO_SIGNUPS_MATCH_EMAIL` the association was just restored). Made the change only for `User` but it probably would apply to most table.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/vaultwarden#368