BerriAI/litellm · error · Exception
Not connected to DB!
Error message
Not connected to DB!
What it means
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.
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)
Example fix
# before
emails = await get_all_team_member_emails(team_id)
# after
from litellm.proxy.proxy_server import prisma_client
emails = (
await get_all_team_member_emails(team_id)
if prisma_client is not None
else []
) Defensive patterns
Strategy: validation
Validate before calling
from litellm.proxy.proxy_server import prisma_client
async def safe_team_emails(team_id: str | None) -> list:
if team_id is None or prisma_client is None:
return []
return await get_all_team_member_emails(team_id) Try / catch
try:
emails = await get_all_team_member_emails(team_id)
except Exception as e:
if 'Not connected to DB' in str(e):
logger.warning('team email alerts skipped; proxy has no database')
emails = []
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Database not connected
- Database not connected. Connect a database to your proxy -…
- Database not connected
- Database not connected. Connect a database to your proxy -…
- Database not connected. Connect a database to your proxy -…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/91d081f717c471d7.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/email_alerting.py:24
from typing import Final
from litellm._logging import verbose_logger, verbose_proxy_logger
from litellm.proxy._types import WebhookEvent
from litellm.repositories.team_repository import TeamRepository
# we use this for the email header, please send a test email if you change this. verify it looks good on email
LITELLM_LOGO_URL: Final = "https://litellm-listing.s3.amazonaws.com/litellm_logo.png"
LITELLM_SUPPORT_CONTACT: Final = "support@berri.ai"
async def get_all_team_member_emails(team_id: str | None = None) -> list:
verbose_logger.debug("Email Alerting: Getting all team members for team_id=%s", team_id)
if team_id is None:
return []
from litellm.proxy.proxy_server import prisma_client
if prisma_client is None:
raise Exception("Not connected to DB!")
team_row: Final = await TeamRepository(prisma_client).table.find_unique(
where={
"team_id": team_id,
}
)
if team_row is None:
return []
_team_members: Final = team_row.members_with_roles
verbose_logger.debug(
"Email Alerting: Got team members for team_id=%s Team Members: %s",
team_id,
_team_members,
)
_team_member_user_ids: Final[list[str]] = []
for member in _team_members:View on GitHub (pinned to 77b7c6c40c)