From 112226938dc42c9b227e79a2bf91432d90be2001 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 28 Mar 2026 12:39:26 +0100 Subject: [PATCH] fix: Convert goal values to float before progress calculation TypeError: unsupported operand type(s) for -: 'decimal.Decimal' and 'float' PostgreSQL NUMERIC columns return Decimal objects. Must convert current_value, target_value, start_value to float before passing to calculate_goal_progress_pct(). Co-Authored-By: Claude Opus 4.6 --- backend/calculations/body_metrics.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/calculations/body_metrics.py b/backend/calculations/body_metrics.py index 8a20d9a..af1a138 100644 --- a/backend/calculations/body_metrics.py +++ b/backend/calculations/body_metrics.py @@ -400,6 +400,10 @@ def _score_weight_trend(profile_id: str) -> Optional[int]: if None in [current, target]: return None + # Convert Decimal to float (PostgreSQL NUMERIC returns Decimal) + current = float(current) + target = float(target) + # If no start_value, use oldest weight in last 90 days if start is None: with get_db() as conn: @@ -414,6 +418,8 @@ def _score_weight_trend(profile_id: str) -> Optional[int]: """, (profile_id,)) row = cur.fetchone() start = float(row['weight']) if row else current + else: + start = float(start) # Progress percentage progress_pct = calculate_goal_progress_pct(current, target, start)