From 7d627cf128aa231a0ec978cd3429a0971405b9ce Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 22 Mar 2026 16:38:39 +0100 Subject: [PATCH] fix: wrap rest_config dict with Json() for psycopg2 JSONB insert Error: psycopg2.ProgrammingError: can't adapt type 'dict' Solution: Import psycopg2.extras.Json and wrap config_dict Changes: - Import Json from psycopg2.extras - Wrap config_dict with Json() in INSERT - Wrap config_dict with Json() in UPDATE Co-Authored-By: Claude Opus 4.6 --- backend/routers/rest_days.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/routers/rest_days.py b/backend/routers/rest_days.py index 3177a0e..3fef4cd 100644 --- a/backend/routers/rest_days.py +++ b/backend/routers/rest_days.py @@ -9,6 +9,7 @@ from datetime import datetime, timedelta from fastapi import APIRouter, HTTPException, Depends, Header from pydantic import BaseModel, Field +from psycopg2.extras import Json from db import get_db, get_cursor, r2d from auth import require_auth @@ -103,7 +104,7 @@ def create_rest_day( note = EXCLUDED.note RETURNING id, profile_id, date, rest_config, note, created_at """, - (pid, data.date, config_dict, data.note) + (pid, data.date, Json(config_dict), data.note) ) result = cur.fetchone() @@ -161,7 +162,7 @@ def update_rest_day( if data.rest_config: updates.append("rest_config = %s") - values.append(data.rest_config.model_dump()) + values.append(Json(data.rest_config.model_dump())) if data.note is not None: updates.append("note = %s")