Skip to content

Commit dffb45c

Browse files
michael.yakmichaelyaakoby
authored andcommitted
Lastest fastapi is having issues rendering nested dataclasses
FastAPI is not properly encoding the nexted HealthSummary - child members/keys aren't included. Once method's return changed to `object` the JSON is rendered as expected.
1 parent bcd08f1 commit dffb45c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pyctuator/impl/fastapi_pyctuator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from collections import defaultdict
23
from datetime import datetime
34
from http import HTTPStatus
@@ -21,6 +22,8 @@
2122
from pyctuator.metrics.metrics_provider import Metric, MetricNames
2223
from pyctuator.threads.thread_dump_provider import ThreadDump
2324

25+
from dataclasses import asdict
26+
2427

2528
class FastApiLoggerItem(BaseModel):
2629
configuredLevel: Optional[str]
@@ -74,7 +77,7 @@ def get_info() -> Dict:
7477
return pyctuator_impl.get_app_info()
7578

7679
@router.get("/health", include_in_schema=include_in_openapi_schema, tags=["pyctuator"])
77-
def get_health(response: Response) -> HealthSummary:
80+
def get_health(response: Response) -> object:
7881
health = pyctuator_impl.get_health()
7982
response.status_code = health.http_status()
8083
return health

0 commit comments

Comments
 (0)