fix: convert Decimal to float in API responses instead of string — fixes positions page crash
This commit is contained in:
@@ -82,10 +82,17 @@ app.add_middleware(TraceMiddleware)
|
|||||||
|
|
||||||
def _row_to_dict(row: asyncpg.Record) -> dict[str, Any]:
|
def _row_to_dict(row: asyncpg.Record) -> dict[str, Any]:
|
||||||
"""Convert an asyncpg Record to a JSON-safe dict."""
|
"""Convert an asyncpg Record to a JSON-safe dict."""
|
||||||
|
from decimal import Decimal
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
d: dict[str, Any] = {}
|
d: dict[str, Any] = {}
|
||||||
for key, val in dict(row).items():
|
for key, val in dict(row).items():
|
||||||
if isinstance(val, datetime):
|
if isinstance(val, datetime):
|
||||||
d[key] = val.isoformat()
|
d[key] = val.isoformat()
|
||||||
|
elif isinstance(val, Decimal):
|
||||||
|
d[key] = float(val)
|
||||||
|
elif isinstance(val, UUID):
|
||||||
|
d[key] = str(val)
|
||||||
elif hasattr(val, "__str__") and not isinstance(val, (str, int, float, bool, list, dict, type(None))):
|
elif hasattr(val, "__str__") and not isinstance(val, (str, int, float, bool, list, dict, type(None))):
|
||||||
d[key] = str(val)
|
d[key] = str(val)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user