From 370f0d46c77c73951f555721986b60684cd17943 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 28 Mar 2026 14:33:16 +0100 Subject: [PATCH] debug: extensive logging for start_date persistence - Log UPDATE SQL and parameters - Verify saved values after UPDATE - Show date types in list_goals response - Track down why start_date not visible in UI --- backend/routers/goals.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/routers/goals.py b/backend/routers/goals.py index 829c5a0..aa87a27 100644 --- a/backend/routers/goals.py +++ b/backend/routers/goals.py @@ -349,6 +349,11 @@ def list_goals(session: dict = Depends(require_auth)): goals = [r2d(row) for row in cur.fetchall()] print(f"[DEBUG] Loaded {len(goals)} goals for profile {pid}") + # Debug: Show first goal with dates + if goals: + first = goals[0] + print(f"[DEBUG] First goal dates: start_date={first.get('start_date')} (type: {type(first.get('start_date'))}), target_date={first.get('target_date')} (type: {type(first.get('target_date'))})") + # Update current values for each goal for goal in goals: try: @@ -580,10 +585,19 @@ def update_goal(goal_id: str, data: GoalUpdate, session: dict = Depends(require_ updates.append("updated_at = NOW()") params.extend([goal_id, pid]) - cur.execute( - f"UPDATE goals SET {', '.join(updates)} WHERE id = %s AND profile_id = %s", - tuple(params) - ) + update_sql = f"UPDATE goals SET {', '.join(updates)} WHERE id = %s AND profile_id = %s" + print(f"[DEBUG] UPDATE SQL: {update_sql}") + print(f"[DEBUG] UPDATE params: {params}") + + cur.execute(update_sql, tuple(params)) + + # Verify what was actually saved + cur.execute(""" + SELECT id, goal_type, start_date, start_value, target_date, target_value + FROM goals WHERE id = %s + """, (goal_id,)) + saved_goal = cur.fetchone() + print(f"[DEBUG] After UPDATE, goal in DB: {r2d(saved_goal)}") return {"message": "Ziel aktualisiert"}