Jellyfin Forum
Error While Updating User Policy - SQLite NOT NULL Constraint Violation - Printable Version

+- Jellyfin Forum (https://forum.jellyfin.org)
+-- Forum: Support (https://forum.jellyfin.org/f-support)
+--- Forum: Troubleshooting (https://forum.jellyfin.org/f-troubleshooting)
+--- Thread: Error While Updating User Policy - SQLite NOT NULL Constraint Violation (/t-error-while-updating-user-policy-sqlite-not-null-constraint-violation)



Error While Updating User Policy - SQLite NOT NULL Constraint Violation - tinker - 2023-07-04

Hello,

I have been trying to programmatically disable a user via the API and encountered a server-side error that I am unable to resolve.

I am using the following Python script to make a POST request to the "/Users/{user_id}/Policy" endpoint:

Code:
import json
import requests

# The server_url, api_key, and user_id can be defined as variables in this script
server_url = "YOUR_SERVER_URL"
api_key = "YOUR_API_KEY"
user_id = "YOUR_USER_ID"

# Construct the URL and headers for the request
url = f'{server_url}/Users/{user_id}/Policy'
headers = {
    'X-MediaBrowser-Token': api_key,
    'Content-Type': 'application/json',
    'X-Emby-Authorization': f'Emby UserId="{user_id}", Client="API", Device="API", DeviceId="API", Version="1.0"'
}
data = {
    "IsDisabled": True
}

# Send the request to the Jellyfin server
response = requests.post(url, headers=headers, data=json.dumps(data))

# If the response status code is not 200, print an error message
if response.status_code != 200:
    print(f'Error from Jellyfin server: {response.text}')
else:
    # Print the JSON response from the Jellyfin server
    print(json.dumps(response.json()))

Despite the user being successfully disabled, the script is returning a server-side error message that says: "Error processing request.".

When checking the server logs, I found the following error:

Code:
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
---> Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 19: 'NOT NULL constraint failed: Users.AuthenticationProviderId'.

It seems like the server is trying to set the AuthenticationProviderId field of the Users table to NULL, which is causing a NOT NULL constraint violation. As this appears to be an issue with the server's attempt to process the request and update its database, I'm unsure how to proceed to rectify this.

Does anyone have any idea what's going on here or if I'm doing something wrong?

Thank you.


RE: Error While Updating User Policy - SQLite NOT NULL Constraint Violation - crobibero - 2023-07-04

You can either query the database directly or visit each user on the dashboard. At least one of them is missing the AuthenticationProvider.