{"record":{"id":"91d081f717c471d7","repo":"BerriAI/litellm","slug":"not-connected-to-db","errorCode":null,"errorMessage":"Not connected to DB!","messagePattern":"Not connected to DB!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/email_alerting.py","lineNumber":24,"sourceCode":"from typing import Final\n\nfrom litellm._logging import verbose_logger, verbose_proxy_logger\nfrom litellm.proxy._types import WebhookEvent\nfrom litellm.repositories.team_repository import TeamRepository\n\n# we use this for the email header, please send a test email if you change this. verify it looks good on email\nLITELLM_LOGO_URL: Final = \"https://litellm-listing.s3.amazonaws.com/litellm_logo.png\"\nLITELLM_SUPPORT_CONTACT: Final = \"support@berri.ai\"\n\n\nasync def get_all_team_member_emails(team_id: str | None = None) -> list:\n    verbose_logger.debug(\"Email Alerting: Getting all team members for team_id=%s\", team_id)\n    if team_id is None:\n        return []\n    from litellm.proxy.proxy_server import prisma_client\n\n    if prisma_client is None:\n        raise Exception(\"Not connected to DB!\")\n\n    team_row: Final = await TeamRepository(prisma_client).table.find_unique(\n        where={\n            \"team_id\": team_id,\n        }\n    )\n\n    if team_row is None:\n        return []\n\n    _team_members: Final = team_row.members_with_roles\n    verbose_logger.debug(\n        \"Email Alerting: Got team members for team_id=%s Team Members: %s\",\n        team_id,\n        _team_members,\n    )\n    _team_member_user_ids: Final[list[str]] = []\n    for member in _team_members:","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/email_alerting.py#L6-L42","documentation":"get_all_team_member_emails imports the proxy's prisma_client from litellm.proxy.proxy_server; when the proxy runs without a database connected, that module-level global is None and this function raises a generic Exception('Not connected to DB!'). It only reaches the DB when team_id is not None, so DB-less deployments only fail once team-scoped email alerts fire.","triggerScenarios":"Enabling email alerting for team budgets/spend on a proxy started without DATABASE_URL; calling get_all_team_member_emails('team-123') directly in tests without initializing prisma_client; alert templates that include team emails while the deployment is auth-less.","commonSituations":"Trying email alerts on a local/dev proxy with no Postgres; DATABASE_URL set but the proxy started before Prisma connected (race during startup); config copied from a DB-backed instance into a DB-less one.","solutions":["Connect a database to the proxy (set DATABASE_URL and restart) so prisma_client is initialized","If DB-less on purpose, disable team-based email alerting thresholds","Guard callers: check litellm.proxy.proxy_server.prisma_client is not None before invoking","Catch the Exception and degrade gracefully (skip team members, alert admins only)"],"exampleFix":"# before\nemails = await get_all_team_member_emails(team_id)\n\n# after\nfrom litellm.proxy.proxy_server import prisma_client\nemails = (\n    await get_all_team_member_emails(team_id)\n    if prisma_client is not None\n    else []\n)","handlingStrategy":"validation","validationCode":"from litellm.proxy.proxy_server import prisma_client\n\nasync def safe_team_emails(team_id: str | None) -> list:\n    if team_id is None or prisma_client is None:\n        return []\n    return await get_all_team_member_emails(team_id)","typeGuard":null,"tryCatchPattern":"try:\n    emails = await get_all_team_member_emails(team_id)\nexcept Exception as e:\n    if 'Not connected to DB' in str(e):\n        logger.warning('team email alerts skipped; proxy has no database')\n        emails = []\n    else:\n        raise","preventionTips":["Decide up front: DB-backed proxy or not; disable team-scoped email alerts on DB-less deployments","Surface 'database connected' state in health checks so alerting misconfig is visible","Set DATABASE_URL before proxy startup, not after"],"tags":["litellm","proxy","email-alerting","prisma","database"],"backgroundTag":"database-not-connected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}