fix: convert empty strings to None for TIME fields in sleep router
All checks were successful
Deploy Development / deploy (push) Successful in 43s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s

PostgreSQL TIME type doesn't accept empty strings.
Converting empty bedtime/wake_time to None before INSERT/UPDATE.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Lars 2026-03-22 08:28:44 +01:00
parent 39d676e5c8
commit 836bc4294b

View File

@ -164,6 +164,10 @@ def create_sleep(
"""Create or update sleep entry (upsert by date)."""
pid = session['profile_id']
# Convert empty strings to None for TIME fields
bedtime = data.bedtime if data.bedtime else None
wake_time = data.wake_time if data.wake_time else None
with get_db() as conn:
cur = get_cursor(conn)
@ -191,7 +195,7 @@ def create_sleep(
updated_at = CURRENT_TIMESTAMP
RETURNING *
""", (
pid, data.date, data.bedtime, data.wake_time, data.duration_minutes,
pid, data.date, bedtime, wake_time, data.duration_minutes,
data.quality, data.wake_count, data.deep_minutes, data.rem_minutes,
data.light_minutes, data.awake_minutes, data.note, data.source
))
@ -210,6 +214,10 @@ def update_sleep(
"""Update existing sleep entry by ID."""
pid = session['profile_id']
# Convert empty strings to None for TIME fields
bedtime = data.bedtime if data.bedtime else None
wake_time = data.wake_time if data.wake_time else None
with get_db() as conn:
cur = get_cursor(conn)
@ -230,7 +238,7 @@ def update_sleep(
WHERE id = %s AND profile_id = %s
RETURNING *
""", (
data.date, data.bedtime, data.wake_time, data.duration_minutes,
data.date, bedtime, wake_time, data.duration_minutes,
data.quality, data.wake_count, data.deep_minutes, data.rem_minutes,
data.light_minutes, data.awake_minutes, data.note, id, pid
))