{"record":{"id":"2c6ceca64a038fed","repo":"BerriAI/litellm","slug":"database-not-connected-2c6cec","errorCode":null,"errorMessage":"Database not connected","messagePattern":"Database not connected","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"litellm/proxy/management_endpoints/internal_user_endpoints.py","lineNumber":1735,"sourceCode":"    \n    Example request for all users:\n    ```bash\n    curl --location 'http://0.0.0.0:4000/user/bulk_update' \\\n    --header 'Authorization: Bearer sk-1234' \\\n    --header 'Content-Type: application/json' \\\n    --data '{\n        \"all_users\": true,\n        \"user_updates\": {\n            \"user_role\": \"internal_user\",\n            \"max_budget\": 50.0\n        }\n    }'\n    ```\n    \"\"\"\n    from litellm.proxy.proxy_server import litellm_proxy_admin_name, prisma_client\n\n    if prisma_client is None:\n        raise HTTPException(\n            status_code=500,\n            detail={\"error\": \"Database not connected\"},\n        )\n\n    # Only proxy admins can modify user_role in bulk updates\n    _bulk_role = getattr(data.user_updates, \"user_role\", None) if data.user_updates else None\n    if _bulk_role is None and data.users:\n        _bulk_role = next((u.user_role for u in data.users if u.user_role is not None), None)\n    if _bulk_role is not None and user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN.value:\n        raise HTTPException(\n            status_code=403,\n            detail=\"Only proxy admins can modify user roles.\",\n        )\n\n    # Determine the list of users to update\n    users_to_update: list[UpdateUserRequest] | list[UpdateUserRequestNoUserIDorEmail] = []\n\n    if data.all_users and data.user_updates:","sourceCodeStart":1717,"sourceCodeEnd":1753,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/internal_user_endpoints.py#L1717-L1753","documentation":"POST /user/bulk_update requires a database; with prisma_client None it returns HTTP 500 {'error': 'Database not connected'} before touching any user. The endpoint otherwise applies user_updates (optionally across all_users) and enforces admin-only role changes with the same 'Only proxy admins can modify user roles.' error.","triggerScenarios":"POST /user/bulk_update (including the all_users: true form shown in its docstring) on a proxy started without general_settings.database_url / DATABASE_URL, or whose Prisma connection failed.","commonSituations":"Bulk onboarding scripts pointed at a proxy instance without Postgres config; the DATABASE_URL env var missing in the cron job's or container's environment; config.yaml only containing model_list.","solutions":["Set general_settings.database_url (postgresql://...) or DATABASE_URL and restart the proxy","Confirm the DB is reachable via GET /health/liveliness or GET /user/list","Re-run the bulk job after the health check shows the database connected"],"exampleFix":"# before\nPOST /user/bulk_update -d '{\"all_users\": true, \"user_updates\": {\"max_budget\": 50}}'\n# 500 Database not connected\n\n# after: config.yaml\ngeneral_settings:\n  database_url: postgresql://user:pass@host:5432/litellm\n# restart proxy, retry -> 200","handlingStrategy":"validation","validationCode":"import requests\n\ndef db_ready(base_url: str, admin_key: str) -> bool:\n    r = requests.get(f\"{base_url}/health/liveliness\",\n                     headers={\"Authorization\": f\"Bearer {admin_key}\"}, timeout=10)\n    return r.ok and r.json().get(\"litellm_database\", \"\") != \"\"","typeGuard":null,"tryCatchPattern":"except requests.HTTPError as e:\n    body = e.response.text if e.response is not None else \"\"\n    if e.response is not None and e.response.status_code == 500 and \"Database not connected\" in body:\n        raise ConfigError(\"bulk user updates need DATABASE_URL configured\") from e\n    raise","preventionTips":["Run bulk jobs only after a /health/liveliness DB check passes","Inject DATABASE_URL explicitly in cron/container environments","Prefer DB-backed deployments for any user-management automation"],"tags":["litellm","database","bulk-update","config"],"backgroundTag":"database-not-connected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}