Foreign key constraint violation upon deleting organization with group #1505

Closed
opened 2026-02-05 01:06:06 +03:00 by OVERLORD · 6 comments
Owner

Originally created by @phiekl on GitHub (Feb 15, 2023).

Subject of the issue

Unable to delete organizations containing groups (with the groups beta feature enabled).

Deployment environment

  • vaultwarden version: 1.27.0-1ba8275d (HEAD)

  • Install method: Built from source

  • Clients used: web vault

  • Reverse proxy and version: nginx (1.18.0-6.1+deb11u3)

  • MySQL/MariaDB or PostgreSQL version: postgres-13 (13.9-0+deb11u1)

  • Environment variables:

    ADMIN_TOKEN=...
    DATABASE_URL=...
    DISABLE_2FA_REMEMBER=false
    DISABLE_ADMIN_TOKEN=true
    DOMAIN=...
    LOGIN_RATELIMIT_MAX_BURST=10
    LOGIN_RATELIMIT_SECONDS=60
    LOG_LEVEL=info
    LOG_TIMESTAMP_FORMAT=''
    ORG_CREATION_USERS=all
    ORG_GROUPS_ENABLED=true
    PASSWORD_HINTS_ALLOWED=false
    REQUIRE_DEVICE_EMAIL=true
    SENDS_ALLOWED=true
    SIGNUPS_ALLOWED=true
    SIGNUPS_DOMAINS_WHITELIST=...
    SIGNUPS_VERIFY=true
    SIGNUPS_VERIFY_RESEND_TIME=300
    SMTP_FROM=...
    SMTP_FROM_NAME=...
    SMTP_HOST=...
    SMTP_PASSWORD=...
    SMTP_PORT=25
    SMTP_SECURITY=starttls
    SMTP_USERNAME=...
    TRASH_AUTO_DELETE_DAYS=30
    USER_ATTACHMENT_LIMIT=131072
    WEBSOCKET_ENABLED=true
    WEBSOCKET_PORT=127.0.0.1
    

Steps to reproduce

  1. Create a new organization.
  2. Create a group within the new organization.
  3. Try to remove the organization. Nothing happens.
  4. Try to remove it via admin interface, same thing.

Expected behaviour

Organization removed.

Actual behaviour

Organization not removed.

Troubleshooting data

Related log entries in systemd journal:

vaultwarden[3206]: [][request][INFO] DELETE /api/organizations/fbeabd5b-3d65-4b29-9881-37ba2a15d270
postgres[3226]: [9-1] 1676417219.784 [3226] vaultwarden@vaultwarden ERROR:  update or delete on table "organizations" violates foreign key constraint "groups_organizations_uuid_fkey" on table "groups"
postgres[3226]: [9-2] 1676417219.784 [3226] vaultwarden@vaultwarden DETAIL:  Key (uuid)=(fbeabd5b-3d65-4b29-9881-37ba2a15d270) is still referenced from table "groups".
postgres[3226]: [9-3] 1676417219.784 [3226] vaultwarden@vaultwarden STATEMENT:  DELETE  FROM "organizations" WHERE ("organizations"."uuid" = $1) 
vaultwarden[3206]: [][error][ERROR] Error saving organization.
vaultwarden[3206]: [CAUSE] DatabaseError(
vaultwarden[3206]:     ForeignKeyViolation,
vaultwarden[3206]:     "update or delete on table \"organizations\" violates foreign key constraint \"groups_organizations_uuid_fkey\" on table \"groups\"",
vaultwarden[3206]: )
vaultwarden[3206]: [][response][INFO] (delete_organization) DELETE /api/organizations/<org_id> => 400 Bad Request
Originally created by @phiekl on GitHub (Feb 15, 2023). ### Subject of the issue Unable to delete organizations containing groups (with the groups beta feature enabled). ### Deployment environment * vaultwarden version: 1.27.0-1ba8275d (HEAD) * Install method: Built from source * Clients used: web vault * Reverse proxy and version: nginx (1.18.0-6.1+deb11u3) * MySQL/MariaDB or PostgreSQL version: postgres-13 (13.9-0+deb11u1) * Environment variables: ``` ADMIN_TOKEN=... DATABASE_URL=... DISABLE_2FA_REMEMBER=false DISABLE_ADMIN_TOKEN=true DOMAIN=... LOGIN_RATELIMIT_MAX_BURST=10 LOGIN_RATELIMIT_SECONDS=60 LOG_LEVEL=info LOG_TIMESTAMP_FORMAT='' ORG_CREATION_USERS=all ORG_GROUPS_ENABLED=true PASSWORD_HINTS_ALLOWED=false REQUIRE_DEVICE_EMAIL=true SENDS_ALLOWED=true SIGNUPS_ALLOWED=true SIGNUPS_DOMAINS_WHITELIST=... SIGNUPS_VERIFY=true SIGNUPS_VERIFY_RESEND_TIME=300 SMTP_FROM=... SMTP_FROM_NAME=... SMTP_HOST=... SMTP_PASSWORD=... SMTP_PORT=25 SMTP_SECURITY=starttls SMTP_USERNAME=... TRASH_AUTO_DELETE_DAYS=30 USER_ATTACHMENT_LIMIT=131072 WEBSOCKET_ENABLED=true WEBSOCKET_PORT=127.0.0.1 ``` ### Steps to reproduce 1. Create a new organization. 2. Create a group within the new organization. 3. Try to remove the organization. Nothing happens. 4. Try to remove it via admin interface, same thing. ### Expected behaviour Organization removed. ### Actual behaviour Organization not removed. ### Troubleshooting data Related log entries in systemd journal: ``` vaultwarden[3206]: [][request][INFO] DELETE /api/organizations/fbeabd5b-3d65-4b29-9881-37ba2a15d270 postgres[3226]: [9-1] 1676417219.784 [3226] vaultwarden@vaultwarden ERROR: update or delete on table "organizations" violates foreign key constraint "groups_organizations_uuid_fkey" on table "groups" postgres[3226]: [9-2] 1676417219.784 [3226] vaultwarden@vaultwarden DETAIL: Key (uuid)=(fbeabd5b-3d65-4b29-9881-37ba2a15d270) is still referenced from table "groups". postgres[3226]: [9-3] 1676417219.784 [3226] vaultwarden@vaultwarden STATEMENT: DELETE FROM "organizations" WHERE ("organizations"."uuid" = $1) vaultwarden[3206]: [][error][ERROR] Error saving organization. vaultwarden[3206]: [CAUSE] DatabaseError( vaultwarden[3206]: ForeignKeyViolation, vaultwarden[3206]: "update or delete on table \"organizations\" violates foreign key constraint \"groups_organizations_uuid_fkey\" on table \"groups\"", vaultwarden[3206]: ) vaultwarden[3206]: [][response][INFO] (delete_organization) DELETE /api/organizations/<org_id> => 400 Bad Request ```
OVERLORD added the good first issuebug labels 2026-02-05 01:06:06 +03:00
Author
Owner

@BlackDex commented on GitHub (Feb 15, 2023):

Please check: https://github.com/dani-garcia/vaultwarden/wiki/Using-the-MariaDB-%28MySQL%29-Backend#foreign-key-errors-collation-and-charset and see if that solves the issue.

@BlackDex commented on GitHub (Feb 15, 2023): Please check: https://github.com/dani-garcia/vaultwarden/wiki/Using-the-MariaDB-%28MySQL%29-Backend#foreign-key-errors-collation-and-charset and see if that solves the issue.
Author
Owner

@phiekl commented on GitHub (Feb 15, 2023):

I'm using postgresql though, and as far as I can see collate and ctype is set to en_US.utf8.

@phiekl commented on GitHub (Feb 15, 2023): I'm using postgresql though, and as far as I can see collate and ctype is set to en_US.utf8.
Author
Owner

@BlackDex commented on GitHub (Feb 15, 2023):

Ah, sorry overlooked that. Ill see if i can reproduce that.

@BlackDex commented on GitHub (Feb 15, 2023): Ah, sorry overlooked that. Ill see if i can reproduce that.
Author
Owner

@Misterbabou commented on GitHub (Feb 16, 2023):

Hello,

I have exactly the same issue using MariaDB : 10.10.2

Impossible te delete organization with groups ( if I remove all group manually before deleting organization it works as expected)

Error message:

vaultwarden    | [2023-02-16 10:03:44.408][error][ERROR] Error saving organization.
vaultwarden    | [CAUSE] DatabaseError(
vaultwarden    |     ForeignKeyViolation,
vaultwarden    |     "Cannot delete or update a parent row: a foreign key constraint fails (`vaultwarden`.`groups`, CONSTRAINT `groups_ibfk_1` FOREIGN KEY (`organizations_uuid`) REFERENCES `organizations` (`uuid`))",
vaultwarden    | )
@Misterbabou commented on GitHub (Feb 16, 2023): Hello, I have exactly the same issue using MariaDB : 10.10.2 Impossible te delete organization with groups ( if I remove all group manually before deleting organization it works as expected) Error message: ``` vaultwarden | [2023-02-16 10:03:44.408][error][ERROR] Error saving organization. vaultwarden | [CAUSE] DatabaseError( vaultwarden | ForeignKeyViolation, vaultwarden | "Cannot delete or update a parent row: a foreign key constraint fails (`vaultwarden`.`groups`, CONSTRAINT `groups_ibfk_1` FOREIGN KEY (`organizations_uuid`) REFERENCES `organizations` (`uuid`))", vaultwarden | ) ```
Author
Owner

@BlackDex commented on GitHub (Feb 16, 2023):

Looks like groups are not deleted during the organization delete function, that is what is causing the issue.
Thanks for reporting.

@BlackDex commented on GitHub (Feb 16, 2023): Looks like groups are **not** deleted during the organization delete function, that is what is causing the issue. Thanks for reporting.
Author
Owner

@BlackDex commented on GitHub (Feb 16, 2023):

PR Created which fixes this issue.

@BlackDex commented on GitHub (Feb 16, 2023): PR Created which fixes this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/vaultwarden#1505