From 78437b649f43be26883b1180e5945931b283d3a4 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 28 Mar 2026 11:23:40 +0100 Subject: [PATCH] fix: Phase 0b - PostgreSQL Decimal type handling TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float' TypeError: unsupported operand type(s) for -: 'float' and 'decimal.Decimal' PostgreSQL NUMERIC/DECIMAL columns return decimal.Decimal objects, not float. These cannot be mixed in arithmetic operations. Fixed 3 locations: - Line 62: float(weight_row['weight']) * 32.5 - Line 153: float(weight_row['weight']) for protein_per_kg - Line 202: float(weight_row['avg_weight']) for adequacy calc Co-Authored-By: Claude Opus 4.6 --- backend/calculations/nutrition_metrics.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/calculations/nutrition_metrics.py b/backend/calculations/nutrition_metrics.py index 84735a8..8ee66d0 100644 --- a/backend/calculations/nutrition_metrics.py +++ b/backend/calculations/nutrition_metrics.py @@ -59,7 +59,7 @@ def calculate_energy_balance_7d(profile_id: str) -> Optional[float]: # Simple TDEE estimate: bodyweight (kg) × 30-35 # TODO: Improve with activity level, age, gender - estimated_tdee = weight_row['weight'] * 32.5 + estimated_tdee = float(weight_row['weight']) * 32.5 balance = avg_intake - estimated_tdee @@ -106,7 +106,7 @@ def calculate_protein_g_per_kg(profile_id: str) -> Optional[float]: if not weight_row: return None - weight = weight_row['weight'] + weight = float(weight_row['weight']) # Get protein intake cur.execute(""" @@ -150,7 +150,7 @@ def calculate_protein_days_in_target(profile_id: str, target_low: float = 1.6, t if not weight_row: return None - weight = weight_row['weight'] + weight = float(weight_row['weight']) # Get protein intake last 7 days cur.execute(""" @@ -199,7 +199,7 @@ def calculate_protein_adequacy_28d(profile_id: str) -> Optional[int]: if not weight_row or not weight_row['avg_weight']: return None - weight = weight_row['avg_weight'] + weight = float(weight_row['avg_weight']) # Get protein intake (28d) cur.execute("""