Skip to content

Commit b4a2797

Browse files
author
Jeremy Ewing
committed
api/settings: accept non-string values and coerce to string
Pydantic rejected numeric/boolean setting updates with 422. Accept any value type and stringify before storing in lux_settings.
1 parent 0afff66 commit b4a2797

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎api/__init__.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import pymysql
1919
from fastapi import FastAPI, HTTPException, Query, WebSocket, WebSocketDisconnect
2020
from pydantic import BaseModel
21+
from typing import Any
2122
from fastapi.middleware.cors import CORSMiddleware
2223
from fastapi.staticfiles import StaticFiles
2324
from starlette.staticfiles import StaticFiles as StarletteStaticFiles
@@ -394,7 +395,7 @@ def api_energy(
394395
# ── settings ────────────────────────────────────────────────────────────────
395396

396397
class SettingUpdate(BaseModel):
397-
value: str
398+
value: Any
398399

399400

400401
@app.get("/api/settings")
@@ -448,8 +449,9 @@ def api_setting_put(name: str, body: SettingUpdate):
448449

449450
conn = _get_conn()
450451
try:
451-
set_(conn, name, body.value)
452-
return {"name": name, "value": body.value, "updated": True}
452+
str_value = str(body.value) if body.value is not None else ""
453+
set_(conn, name, str_value)
454+
return {"name": name, "value": str_value, "updated": True}
453455
finally:
454456
conn.close()
455457

0 commit comments

Comments
 (0)