fix: wrap rest_config dict with Json() for psycopg2 JSONB insert
All checks were successful
Deploy Development / deploy (push) Successful in 49s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s

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 <noreply@anthropic.com>
This commit is contained in:
Lars 2026-03-22 16:38:39 +01:00
parent c265ab1245
commit 7d627cf128

View File

@ -9,6 +9,7 @@ from datetime import datetime, timedelta
from fastapi import APIRouter, HTTPException, Depends, Header from fastapi import APIRouter, HTTPException, Depends, Header
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from psycopg2.extras import Json
from db import get_db, get_cursor, r2d from db import get_db, get_cursor, r2d
from auth import require_auth from auth import require_auth
@ -103,7 +104,7 @@ def create_rest_day(
note = EXCLUDED.note note = EXCLUDED.note
RETURNING id, profile_id, date, rest_config, note, created_at 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() result = cur.fetchone()
@ -161,7 +162,7 @@ def update_rest_day(
if data.rest_config: if data.rest_config:
updates.append("rest_config = %s") 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: if data.note is not None:
updates.append("note = %s") updates.append("note = %s")