superset: cannot delete user "Associated data exists, please delete them first"
When trying to delete a user, the error message “Associated data exists, please delete them first” appears. All charts and dashboards created by that account have been deleted. I have also set the user as inactive and deleted its role setting. I am able to edit the user but not delete it.
I found the following similar issue which was marked as stale with no response: https://github.com/apache/superset/issues/8752
Expected results
Successful deletion of a user
Actual results
“Associated data exists, please delete them first” error message
Logs when navigating to user list and trying to delete user (domain has been replaced with deploymentlink.com): 10.4.15.23 - - [25/Feb/2021:19:48:28 +0000] “GET /users/list/ HTTP/1.1” 200 26741 “deploymentlink.com/superset/welcome” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36” 10.4.15.23 - - [25/Feb/2021:19:48:34 +0000] “POST /users/delete/3 HTTP/1.1” 302 299 “deploymentlink.com/users/list” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36” 10.4.15.23 - - [25/Feb/2021:19:48:34 +0000] “GET /users/list/ HTTP/1.1” 200 26786 “-” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36”
Screenshots

How to reproduce the bug
- Go to ‘List Users’
- Navigate to user row
- Click on ‘Delete’ icon
- See error
Environment
(please complete the following information):
- superset version:
superset version: Superset 0.999.0dev - python version:
python --version: 3.7.9 - node.js version:
node -v: couldn’t find
Checklist
Make sure to follow these steps before submitting your issue - thank you!
- I have checked the superset logs for python stacktraces and included it here as text if there are any.
- I have reproduced the issue with at least the latest released version of superset.
- I have checked the issue tracker for the same issue and I haven’t found one similar.
Additional context
none
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 18
- Comments: 34 (13 by maintainers)
puting this here for future use:
This script has worked for me without problems and I continue to use it. It was written quickly so test it first.
The reason for the select is that I use this with a != on the surname.
Hello, I systematically reproduce the problem “impossible to delete a user : Associated data exists, please delete them first”.
Creation of a user (alpha) + Login of the user + Creation of a chart by the user + Deletion of the chart by the user + Deletion of the user => Associated data exists, please delete them first
I have identified the cause: This only concerns users who have created elements in Superset. Despite the deletion of elements created by a user from the graphical user interface, the deletion of the user is impossible because the “key_value” table is not cleaned at the time of deletion, this creates an integrity constraint preventing the deletion of the user.
The other tables (logs, slices, slice_user) are correctly updated.
The “key_value” table has a relationship only with the “ab_user” table.
It is possible to work around the problem by executing a delete query on the key_value table : delete from public.key_value where created_by_fk = <id_user_to_delete>
Testing the workaround : “Deleted Row” 👍
The following tables are well updated: • ab_user.sql ◦ Deletion of the line relating to the user • ab_user_role.sql ◦ Deletion of the line relating to the user • logs.sql ◦ Lines mentioning <user id> now mention user = None (like a user deleted without objects created)
Best regards
On superset 4.1.1, remove all roles from the user then use this SQL Query:
@rusackas @michael-s-molina @xavier-GitHub76 IMO orphaning the rows is definitely the right course of action here, as permalinks etc should continue existing after a user record is deleted. And for other temporary key value pairs, there’s usually an expiration date attached to them, which will ensure that the records disappear in due course.
Same bug for me on 3.1.0. I have no access to the SuperSet database so I will set the user as inactive. But it should really be fixed.
I ran into the same problem. I can’t delete any user even though the use was recently created and doesn’t own any chart, board or dataset.
How could it be that the user deletion doesn’t cascade through every data like e.g. logs?
Appreciate some solutions (two years after initial report) for how to solve this bug.
I think there’s also a logs table. Tbh deleting a user if quite difficult since cascade hasn’t been set on a lot of the foreign key relationships, so you’ll have to find them and delete the records manually.
If possible, just mark the user as inactive and change all the fields that might cause issues with unique constraints if the same user is trying to sign up again