Repository navigation
Labels
Description
Please verify that this bug has NOT been raised before.
- I checked and didn't find a similar issue
Describe the bug*
As an Admin I want to delete a user but I only get 500 Internal Server Error:
Apparently this is because of a constraint on the session table:
inventree=# select expire_date from user_sessions_session where user_id = 20;
expire_date
-------------------------------
2025-09-22 11:38:03.909674+00
(1 row)Steps to Reproduce
- Register new user
- Login with the new user
- As an Admin, try to delete the user
Expected behaviour
User should be deleted
Deployment Method
Docker
Version Information
InvenTree-Version: 1.0.1
Django Version: 4.2.24
Commit Hash: 6207aa6
Commit Date: 2025-09-19
Commit Branch: null
Database: django.db.backends.postgresql
Debug-Mode: False
Deployed using Docker: True
Platform: Linux-6.1.0-38-amd64-x86_64-with-glibc2.41
Installer: DOC
Active plugins: false
Try to reproduce on the demo site
I did not try to reproduce
Is the bug reproducible on the demo site?
Not reproducible
Relevant log output
2025-09-23 18:06:29,049 INFO {'request': 'DELETE /api/user/20/', 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:143.0) Gecko/20100101 Firefox/143.0', 'event': 'request_started', 'ip': '10.140.0.1', 'request_id': 'd914e5a9-0042-49a8-b222-6c96e9c1b9f3', 'user_id': 1, 'timestamp': '2025-09-23T18:06:29.049501Z', 'logger': 'django_structlog.middlewares.request', 'level': 'info'}
2025-09-23T18:06:29.288633Z [error ] update or delete on table "auth_user" violates foreign key constraint "user_sessions_session_user_id_c6dc9ffa_fk_auth_user_id" on table "user_sessions_session"
DETAIL: Key (id)=(20) is still referenced from table "user_sessions_session". [inventree] ip=10.140.0.1 request_id=d914e5a9-0042-49a8-b222-6c96e9c1b9f3 user_id=1
2025-09-23 18:06:29,288 ERROR {'event': IntegrityError('update or delete on table "auth_user" violates foreign key constraint "user_sessions_session_user_id_c6dc9ffa_fk_auth_user_id" on table "user_sessions_session"\nDETAIL: Key (id)=(20) is still referenced from table "user_sessions_session".'), 'ip': '10.140.0.1', 'request_id': 'd914e5a9-0042-49a8-b222-6c96e9c1b9f3', 'user_id': 1, 'timestamp': '2025-09-23T18:06:29.288633Z', 'logger': 'inventree', 'level': 'error'}
2025-09-23T18:06:29.335153Z [info ] Gathering users for notification 'inventree.error_log' [inventree] ip=10.140.0.1 request_id=d914e5a9-0042-49a8-b222-6c96e9c1b9f3 user_id=1
2025-09-23 18:06:29,335 INFO {'event': "Gathering users for notification 'inventree.error_log'", 'ip': '10.140.0.1', 'request_id': 'd914e5a9-0042-49a8-b222-6c96e9c1b9f3', 'user_id': 1, 'timestamp': '2025-09-23T18:06:29.335153Z', 'logger': 'inventree', 'level': 'info'}
2025-09-23T18:06:29.336341Z [debug ] Checking plugin registry hash [inventree] ip=10.140.0.1 request_id=d914e5a9-0042-49a8-b222-6c96e9c1b9f3 user_id=1
2025-09-23 18:06:29,336 DEBUG {'event': 'Checking plugin registry hash', 'ip': '10.140.0.1', 'request_id': 'd914e5a9-0042-49a8-b222-6c96e9c1b9f3', 'user_id': 1, 'timestamp': '2025-09-23T18:06:29.336341Z', 'logger': 'inventree', 'level': 'debug'}
2025-09-23T18:06:29.379639Z [error ] request_finished [django_structlog.middlewares.request] code=500 ip=10.140.0.1 request='DELETE /api/user/20/' request_id=d914e5a9-0042-49a8-b222-6c96e9c1b9f3 user_id=1
2025-09-23 18:06:29,379 ERROR {'code': 500, 'request': 'DELETE /api/user/20/', 'event': 'request_finished', 'ip': '10.140.0.1', 'request_id': 'd914e5a9-0042-49a8-b222-6c96e9c1b9f3', 'user_id': 1, 'timestamp': '2025-09-23T18:06:29.379639Z', 'logger': 'django_structlog.middlewares.request', 'level': 'error'}
2025-09-23 18:06:29,380 ERROR Internal Server Error: /api/user/20/
10.140.0.1 - - [23/Sep/2025:18:06:29 +0000] "DELETE /api/user/20/ HTTP/1.1" 500 181 "https://inventree.ctbk.de/web/settings/admin/user/" "Mozilla/5.0 (X11; Linux x86_64; rv:143.0) Gecko/20100101 Firefox/143.0"
Activity
matmair commentedon Sep 23, 2025
Can reproduce, fix incoming
CobaltDragonGit commentedon Sep 24, 2025
Does this fix also solves the issue of not being able to manually delete access tokens ?
matmair commentedon Sep 24, 2025
No, only the mentioned things were closed by the PR
CobaltDragonGit commentedon Sep 24, 2025
I had the same issue as p-fruck. I thought the user couldn't be deleted because of the access token so I deleted it manually. I noticed then the table kept the row of the deleted token. Looks like it doesn't seem related.
I opened a new bug report at #10391
joelidrive commentedon Oct 30, 2025
@matmair
Hello, looks like I am experiencing this same exact issue but I am on version 1.0.8 on a docker deployment. This is the error I receive when I try and delete a specific user.
update or delete on table "auth_user" violates foreign key constraint "user_sessions_session_user_id_c6dc9ffa_fk_auth_user_id" on table "user_sessions_session"
DETAIL: Key (id)=(4) is still referenced from table "user_sessions_session".
InvenTree-Version: 1.0.8
Django Version: 4.2.25
Commit Hash: 0dcb706
Commit Date: 2025-10-21
Commit Branch: null
Database: django.db.backends.postgresql
Debug-Mode: False
Deployed using Docker: True
Platform: Linux-6.12.48+deb13-cloud-amd64-x86_64-with-glibc2.41
Installer: DOC
Active plugins: [{"name":"InvenTreeBarcode","slug":"inventreebarcode","version":"2.1.0"},{"name":"BOM Exporter","slug":"bom-exporter","version":"1.1.0"},{"name":"InvenTree Exporter","slug":"inventree-exporter","version":"1.0.0"},{"name":"Part Parameter Exporter","slug":"parameter-exporter","version":"1.0.0"},{"name":"InvenTreeEmailNotifications","slug":"inventree-email-notification","version":"1.0.0"},{"name":"InvenTreeUINotifications","slug":"inventree-ui-notification","version":"1.0.0"},{"name":"InvenTreeCurrencyExchange","slug":"inventreecurrencyexchange","version":"1.0.0"},{"name":"InvenTreeMachines","slug":"inventree-machines","version":"1.0.0"},{"name":"InvenTreeLabel","slug":"inventreelabel","version":"1.1.0"},{"name":"InvenTreeLabelMachine","slug":"inventreelabelmachine","version":"1.0.0"},{"name":"InvenTreeLabelSheet","slug":"inventreelabelsheet","version":"1.0.1"},{"name":"DigiKeyBarcodePlugin","slug":"digikeyplugin","version":"1.0.1"},{"name":"LCSCBarcodePlugin","slug":"lcscplugin","version":"1.0.1"},{"name":"MouserBarcodePlugin","slug":"mouserplugin","version":"1.0.1"},{"name":"TMEBarcodePlugin","slug":"tmeplugin","version":"1.0.1"}]
SchrodingersGat commentedon Oct 31, 2025
I have not been able to reproduce this - @matmair any thoughts?
18 remaining items
matmair commentedon Feb 2, 2026
@SchrodingersGat I can not reproduce this and therefore have no way to fix it; unassigning myself
SchrodingersGat commentedon Feb 11, 2026
@p-fruck we are going to need some more information / reproducability before we can fix this I'm afraid
github-actions commentedon May 20, 2026
This issue seems stale. Please react to show this is still important.
github-actions commentedon Aug 17, 2026
This issue seems stale. Please react to show this is still important.
SchrodingersGat commentedon Aug 21, 2026
@p-fruck see #12675