mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-25 01:02:15 +00:00
fix(mavvrik): raise on DB not connected in Service.export/dry_run
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) <noreply@anthropic.com>
This commit is contained in:
parent
b0a140647f
commit
2bee264939
2 changed files with 9 additions and 3 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue