From 2bee264939f208bbb42ec1ab99585badb6b7c4bf Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Sun, 26 Apr 2026 08:30:50 +0530 Subject: [PATCH] fix(mavvrik): raise on DB not connected in Service.export/dry_run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Service.export() and Service.dry_run() called exporter.export() which silently returns an empty DataFrame when prisma_client is None, causing the endpoint to return {"status": "success", "records_exported": 0} — identical to a legitimate zero-traffic day. Admins had no way to tell the difference. Fix: call Settings._ensure_prisma_client() before reaching the exporter in both methods. This raises an Exception with a clear message when the DB is not connected, surfacing as a 500 response to the caller. Also fixes the misleading exporter.py module docstring which claimed "user-triggered endpoints surface the missing-DB error through Settings._ensure_prisma_client() before reaching here" — that was wrong until this commit. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- litellm/integrations/mavvrik/__init__.py | 4 ++++ litellm/integrations/mavvrik/exporter.py | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/litellm/integrations/mavvrik/__init__.py b/litellm/integrations/mavvrik/__init__.py index 2074004012e..c98aebf22ec 100644 --- a/litellm/integrations/mavvrik/__init__.py +++ b/litellm/integrations/mavvrik/__init__.py @@ -275,6 +275,8 @@ class Service: if not data and not self._settings.has_env_vars: raise ValueError("Mavvrik not configured. Call POST /mavvrik/init first.") + self._settings._ensure_prisma_client() + date_str = date_str or self._yesterday() effective_limit = limit or MAVVRIK_MAX_FETCHED_DATA_RECORDS @@ -326,6 +328,8 @@ class Service: if not data and not self._settings.has_env_vars: raise ValueError("Mavvrik not configured. Call POST /mavvrik/init first.") + self._settings._ensure_prisma_client() + date_str = date_str or self._yesterday() effective_limit = limit or MAVVRIK_MAX_FETCHED_DATA_RECORDS diff --git a/litellm/integrations/mavvrik/exporter.py b/litellm/integrations/mavvrik/exporter.py index 8a2117d11dd..bde7109a73f 100644 --- a/litellm/integrations/mavvrik/exporter.py +++ b/litellm/integrations/mavvrik/exporter.py @@ -14,9 +14,11 @@ Internal methods: _get_usage_data(date_str, limit) → DataFrame _to_csv(df, connection_id) → str -DB not connected: all methods log a warning and return empty/None — never raise. -The scheduler skips the date gracefully; user-triggered endpoints surface the -missing-DB error through Settings._ensure_prisma_client() before reaching here. +DB not connected: + _get_usage_data / _to_csv — log warning and return empty/None (scheduler path). + _stream_pages — raises RuntimeError (propagates to Orchestrator try/except). + Service.export / dry_run — call Settings._ensure_prisma_client() before reaching here, + so they raise before the exporter is called. polars is an optional [proxy] dependency — imported lazily inside methods so SDK-only users are not affected when Logger is imported via custom_logger_registry.