Error deleting user

Hi there,

I recently wanted to delete an account who forgot her password. Normally this is straight forward through the admin page. But now after typing the email for confirmation it shows “error deleting user”.

I can create a new different user and delete it without problem. Only that specific user is somewhat stuck. There is nothing special about that user.

Already restarted the docker container. Still “error deleting user”.
Any other way to delete a user?

Thanks for your help.

What is the specific error?

Quite unspecific. It says
“Error deleting user”
“Error deleting user”

Any logs from Vaultwarden?
Our something else with a bit more information?

Ah, thanks for the hint. Should be the first move to look into the log.
This is always logged upon trying to delete that specific user:

[2023-07-31 23:04:33.949][request][INFO] GET /admin/users/overview
[2023-07-31 23:04:33.952][response][INFO] (users_overview) GET /admin/users/overview => 200 OK
[2023-07-31 23:04:58.949][request][INFO] POST /admin/users/b3883308-1cb5-4854-841a-cbefe993d4f5/delete
[2023-07-31 23:04:58.950][error][ERROR] Error deleting user.
[CAUSE] DatabaseError(
“FOREIGN KEY constraint failed”,
[2023-07-31 23:04:58.950][response][INFO] (delete_user) POST /admin/users//delete => 400 Bad Request

Looks like the user was partially deleted somehow.
Verify that you are using the latest version.

And also check this Using the MariaDB (MySQL) Backend · dani-garcia/vaultwarden Wiki · GitHub

If there are any issues with the collation or charset that could cause issues.

Yes, I am using the latest Version 1.29.1.

Also I am using SQLite. Do the mentioned collation/charset issues also apply to SQLite databases?
And do you think the user can be deleted manually off the db? Or do you suggest switching to a mysql db? Could be a little overkill for our small installation.

What I remember is that the user was a member of a organisation when I tried to delete him. Instead the user was only kicked out of that organisation… and got stuck. Maybe that helps.

Then i suggest to check and verify the integrity of the sqlite file.

Always create a backup before executing commands like this

This is what came out:

sqlite> PRAGMA foreign_key_check;
sqlite> PRAGMA integrity_check;
row 41 missing from index sqlite_autoindex_devices_1
row 42 missing from index sqlite_autoindex_devices_1
row 43 missing from index sqlite_autoindex_devices_1
row 44 missing from index sqlite_autoindex_devices_1
row 45 missing from index sqlite_autoindex_devices_1
wrong # of entries in index sqlite_autoindex_devices_1

And additionally I tried:
sqlite3 db.sqlite3 .dump | sqlite3 db.sqlite3.fix
Error: near line 1531: UNIQUE constraint failed: devices.uuid, devices.user_uuid

Also tried exporting to sql and reimporting but gave me an error similar to the dump while reimporting.

Any suggestion on how to fix this?

Help is still very appreciated…

And now another user cannot be deleted.

Message: Error deleting user
Error removing devices for user

Interestingly the entries of that user seem to be deleted (5 before deletion attempt, 0 after). Only the user still exists…

Thanks for any help.

Corresponding log entries:

vaultwarden | [2023-11-18 16:32:32.572][response][INFO] (disable_user) POST /admin/users//disable => 400 Bad Request
vaultwarden | [2023-11-18 16:33:02.552][request][INFO] GET /admin/users/overview
vaultwarden | [2023-11-18 16:33:02.560][response][INFO] (users_overview) GET /admin/users/overview => 200 OK
vaultwarden | [2023-11-18 16:33:24.194][request][INFO] POST /admin/users/a13899a0-16bb-415a-88d4-xxxxx0b492db/delete
vaultwarden | [2023-11-18 16:33:24.199][error][ERROR] Error removing devices for user.
vaultwarden | [CAUSE] DatabaseError(
vaultwarden | Unknown,
vaultwarden | “database disk image is malformed”,
vaultwarden | )
vaultwarden | [2023-11-18 16:33:24.199][response][INFO] (delete_user) POST /admin/users//delete => 400 Bad Request
vaultwarden | [2023-11-18 16:33:40.206][request][INFO] GET /admin/users/overview
vaultwarden | [2023-11-18 16:33:40.211][response][INFO] (users_overview) GET /admin/users/overview => 200 OK
vaultwarden | [2023-11-18 16:33:52.793][request][INFO] GET /admin/users/overview
vaultwarden | [2023-11-18 16:33:52.798][response][INFO] (users_overview) GET /admin/users/overview => 200 OK
vaultwarden | [2023-11-18 16:37:32.939][request][INFO] POST /admin/users/b3883308-1cb5-4854-841a-xxxxx993d4f5/delete
vaultwarden | [2023-11-18 16:37:32.943][error][ERROR] Error deleting user.
vaultwarden | [CAUSE] DatabaseError(
vaultwarden | ForeignKeyViolation,
vaultwarden | “FOREIGN KEY constraint failed”,
vaultwarden | )

This looks for me like a serious ongoing database problem… right?!

So all I can do is export all the entries of all users manually and import them to a new vaultwarden instance. Right?!

I would suggest to read Using the MariaDB (MySQL) Backend · dani-garcia/vaultwarden Wiki · GitHub

Thanks for that link. That is what you already suggested in August …

Sorry, but what are you actually trying to say?
You think that switching from sqlite to mysql/mariadb could solve these issues?

Sorry was a bit late and didn’t saw correctly you were using sqlite.
You could try to vacume/dumb the database and see if you can use that.

I dumped the sqlite db as shown in the Wiki with no errors.

When trying to import the dump file into an empty mariadb database (docker-compose as in the Wiki) it gives me this error

ERROR 1062 (23000) at line 1354: Duplicate entry ‘7f59903c-4f09-44c2-8f81-d7634ca23e62-00e76681-7f66-40a7-a565-…’ for key ‘PRIMARY’

Can duplicate entries be the reason for my actual problems with deleting users?

Sorry, I am not so much into databases. How can I find and delete this duplicate entry?
Possibly already while/before dumping the sqlite db…?!

I actually ment to dump as a backup and use that backup instead of the possible broken/corrupted database

Yes, there is an automated dump of the sqlite db every night for backup which is than backed up. But I missed the moment the db got corrupted because it is/was still possible to add/delete entries. Only user management is corrupted so far. So I could have restored a backup when the corruption first appeared but nit knowing which and how many entries I would loose… So I decided to go on with the corrupted db.

Already tried dumping and restoring the than latest version of the sqlite db. See my former posts…