{"record":{"id":"e835c6951c3d9423","repo":"BerriAI/litellm","slug":"database-not-connected","errorCode":null,"errorMessage":"Database not connected","messagePattern":"Database not connected","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"enterprise/litellm_enterprise/enterprise_callbacks/send_emails/endpoints.py","lineNumber":124,"sourceCode":"        )\n\n\n@router.get(\n    \"/email/event_settings\",\n    response_model=EmailEventSettingsResponse,\n    tags=[\"email management\"],\n    dependencies=[Depends(user_api_key_auth)],\n)\nasync def get_email_event_settings(\n    user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),\n):\n    \"\"\"\n    Get all email event settings\n    \"\"\"\n    from litellm.proxy.proxy_server import prisma_client\n\n    if prisma_client is None:\n        raise HTTPException(status_code=500, detail=\"Database not connected\")\n\n    try:\n        # Get existing settings\n        settings_dict = await _get_email_settings(prisma_client)\n\n        # Create a response with all events (enabled or disabled)\n        response_settings = []\n        for event in EmailEvent:\n            enabled = settings_dict.get(event.value, False)\n            response_settings.append(EmailEventSettings(event=event, enabled=enabled))\n\n        return EmailEventSettingsResponse(settings=response_settings)\n    except Exception as e:\n        verbose_proxy_logger.exception(f\"Error getting email settings: {str(e)}\")\n        raise HTTPException(status_code=500, detail=str(e))\n\n\n@router.patch(","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/litellm_enterprise/enterprise_callbacks/send_emails/endpoints.py#L106-L142","documentation":"Raised by the GET endpoint for email event settings in LiteLLM Enterprise. The handler imports prisma_client from litellm.proxy.proxy_server and, when it is None (no Prisma database was initialized at proxy startup), returns HTTP 500 with 'Database not connected'. Email event settings are persisted in the database, so the endpoint cannot function without one.","triggerScenarios":"Calling GET on the email event settings endpoint (tagged 'email management', requires user_api_key_auth) on a proxy instance started without DATABASE_URL / a valid Prisma connection. Any deployment where prisma_client never got set (e.g. config missing database_url) hits this on every call.","commonSituations":"Running the proxy in DB-less mode (config-only, no virtual keys) but hitting admin/UI email settings endpoints; DATABASE_URL points at an unreachable PostgreSQL so Prisma init failed silently at startup; testing locally without a database.","solutions":["Set DATABASE_URL (or database_url in the proxy config YAML) to a valid PostgreSQL connection string and restart the proxy so Prisma connects","Verify the DB is up: check /health/liveliness or /health/readiness and prisma migration status before calling the endpoint","If you do not need email event settings, avoid the email management endpoints in DB-less deployments"],"exampleFix":"# before (config.yaml with no database)\ngeneral_settings:\n  master_key: sk-123\n\n# after\n general_settings:\n  master_key: sk-123\nlitellm_settings:\n  database_url: postgresql://user:pass@host:5432/litellm","handlingStrategy":"validation","validationCode":"import httpx\nresp = httpx.get(f'{PROXY_URL}/health/readiness', headers=headers)\nif resp.status_code != 200:\n    raise RuntimeError('Proxy/DB not ready; skip email settings call')","typeGuard":null,"tryCatchPattern":"try:\n    r = httpx.get(f'{PROXY_URL}/email/settings-endpoint', headers=headers)\n    r.raise_for_status()\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code == 500 and 'Database not connected' in e.response.text:\n        # DB missing on proxy: fix config, do not retry\n        raise","preventionTips":["Configure DATABASE_URL before deploying any proxy that will serve admin UI endpoints","Add a startup smoke test that calls /health/readiness before routing traffic","Keep DB-less deployments away from email management endpoints via routing rules"],"tags":["database","prisma","litellm-enterprise","email","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}