{"record":{"id":"3ccf83752bfffdc8","repo":"BerriAI/litellm","slug":"error-saving-email-settings-to-general-settings","errorCode":null,"errorMessage":"Error saving email settings to general_settings: {str(e)}","messagePattern":"Error saving email settings to general_settings: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"enterprise/litellm_enterprise/enterprise_callbacks/send_emails/endpoints.py","lineNumber":103,"sourceCode":"        # Update email_settings in general_settings\n        general_settings[\"email_settings\"] = settings\n\n        # Convert to JSON for storage\n        json_settings = json.dumps(general_settings, default=str)\n\n        # Save updated general settings\n        await prisma_client.db.litellm_config.upsert(\n            where={\"param_name\": \"general_settings\"},\n            data={\n                \"create\": {\n                    \"param_name\": \"general_settings\",\n                    \"param_value\": json_settings,\n                },\n                \"update\": {\"param_value\": json_settings},\n            },\n        )\n    except Exception as e:\n        raise HTTPException(\n            status_code=500,\n            detail=f\"Error saving email settings to general_settings: {str(e)}\",\n        )\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","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/litellm_enterprise/enterprise_callbacks/send_emails/endpoints.py#L85-L121","documentation":"Raised as HTTPException 500 by the enterprise email-settings endpoint (set/update email event settings) when persisting the merged general_settings to the database fails — most commonly at the prisma_client.db.litellm_config.upsert for param_name='general_settings'. The underlying exception string is included in the detail.","triggerScenarios":"Calling the email settings PUT/POST endpoint while the Prisma database is unreachable, the LiteLLM_Config table does not exist (migrations not run), json_settings fails to serialize, or the upsert violates a DB constraint. Any exception in the try block becomes this 500.","commonSituations":"Proxy started without DB migrations (prisma generate/migrate) so litellm_config table is missing; DB credentials wrong or DB restarted mid-request; concurrent writes to general_settings causing serialization issues; non-JSON-serializable values in the merged settings dict.","solutions":["Read {str(e)} in the response detail — it usually names the Prisma error (P1001 connection, P2021 table missing, unique constraint).","Verify DB connectivity and that schema migrations ran (the LiteLLM_Config table exists).","Retry the request once transient DB issues are resolved; the upsert is idempotent.","If serialization is the cause, remove non-serializable values from general_settings and re-save."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"import httpx\n\n# preflight: DB reachable and litellm_config table present\nr = httpx.get(f\"{PROXY_BASE}/health/liveliness\", timeout=5)\nassert r.status_code == 200, \"proxy/db unhealthy — email settings save will fail\"","typeGuard":null,"tryCatchPattern":"for attempt in range(2):\n    try:\n        resp = await client.post(\"/email/event_settings\", json=settings)\n        break\n    except HTTPException as e:\n        if e.status_code == 500 and \"Error saving email settings\" in str(e.detail):\n            await asyncio.sleep(2)  # transient DB issue — one retry (upsert is idempotent)\n            continue\n        raise","preventionTips":["Run prisma migrations before enabling email settings endpoints.","Keep DB credentials in secret management and verify connectivity before API calls.","Ensure general_settings values are JSON-serializable before submission.","Read the embedded {str(e)} detail — Prisma error codes pinpoint the root cause."],"tags":["enterprise","email","database","prisma","http-500"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}