From 1d813e46437c2c86e5975eaec54d9acaaa557dfe Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Mon, 3 Nov 2025 00:15:09 -0500 Subject: [PATCH] [food] Fix error in calorie aggregation --- vrobbler/apps/scrobbles/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vrobbler/apps/scrobbles/utils.py b/vrobbler/apps/scrobbles/utils.py index 386e4ac..942797c 100644 --- a/vrobbler/apps/scrobbles/utils.py +++ b/vrobbler/apps/scrobbles/utils.py @@ -396,11 +396,12 @@ def get_daily_calories_for_user_by_day(user_id: int, date: date| str) -> int: try: qs = base_scrobble_qs(user_id).filter(day=date) - except AttibuteError as e: + agg = qs.aggregate(total_calories=models.Sum("calories_int")) + except AttributeError as e: logger.warning(f"Can't generate calorie total: {e}") - agg = qs.aggregate(total_calories=models.Sum("calories_int")) + agg = {} - return agg["total_calories"] or 0 + return agg.get("total_calories") or 0 def get_daily_calorie_dict_for_user(user_id: int) -> dict[date, int]: """Return {day: total_calories} for all days with scrobbles, in one query."""