fix(mavvrik): fix dry_run TypeError on NULL spend and missing column guard

Bug 1: float(df["spend"].sum()) raises TypeError when all spend values
are NULL — polars .sum() returns None for an all-null series.
Fix: float(df["spend"].sum() or 0.0)

Bug 2: df["completion_tokens"].sum() accessed without checking the column
exists — only "prompt_tokens" was guarded. Raises ColumnNotFoundError if
schema omits completion_tokens.
Fix: guard both columns together before summing.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Praveen Ghuge 2026-04-26 21:52:53 +05:30
parent 2f6742a700
commit 4962c1d62a

View file

@ -387,10 +387,10 @@ class Service:
},
}
total_cost = float(df["spend"].sum()) if "spend" in df.columns else 0.0
total_cost = float(df["spend"].sum() or 0.0) if "spend" in df.columns else 0.0
total_tokens = (
int((df["prompt_tokens"].sum() or 0) + (df["completion_tokens"].sum() or 0))
if "prompt_tokens" in df.columns
if "prompt_tokens" in df.columns and "completion_tokens" in df.columns
else 0
)
unique_models = df["model"].n_unique() if "model" in df.columns else 0