| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…strings The BaseModel branch of EventSerializer returned model_dump() directly, so non-finite floats nested inside a pydantic model bypassed the NaN/Inf sanitizer that the dict/list branches apply. The JSON C encoder then emitted bare NaN/Infinity tokens, which strict JSON parsers reject -- a traced pydantic object carrying a NaN/Inf float produced an event body that failed ingestion. Route the dumped dict back through default() so the same sanitization applies at every nesting depth. Fixes #16048. Signed-off-by: Ruiming Zhao <uuzzrm@gmail.com>
| Back | FazBrowse Home | New Git URL |
What does this PR do?
Fixes #16048
EventSerializer's BaseModel branch returned obj.model_dump() directly, so non-finite floats nested inside a pydantic model bypassed the NaN/Inf sanitizer that the dict/list branches already apply. Python's JSON C encoder then emitted bare NaN/Infinity tokens, which strict JSON parsers reject. On the tracing path, any traced pydantic object carrying a NaN/Inf float (common with ML/scoring payloads) produced an event body that failed ingestion.
The fix routes the dumped dict back through default(), so the same sanitization applies at every nesting depth:
Type of change
Verification
The new regression test test_pydantic_model_with_non_finite_float_serializes_to_valid_json fails before the fix (strict parse raises ValueError: NaN) and passes after. test_path fails on this machine only (POSIX-vs-Windows path separators) and passes in CI's Linux runner; the same pre-existing mypy import-not-found note for langchain_core is present on the unmodified file.
Checklist
Greptile Summary
Routes Pydantic model_dump() output back through EventSerializer so nested non-finite floats become JSON-safe strings.
Confidence Score: 5/5
The PR appears safe to merge, with the intended Pydantic serialization behavior covered by a focused strict-JSON regression test.
The changed branch reuses the established recursive normalization path, ensuring non-finite floats nested in Pydantic models no longer produce invalid bare JSON constants, and no concrete blocking or non-blocking defect remains.
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Pydantic BaseModel] --> B[model_dump] B --> C[EventSerializer recursive normalization] C --> D[NaN and Infinity converted to strings] D --> E[Valid JSON ingestion payload]Reviews (1): Last reviewed commit: "fix: serialize NaN/Inf floats nested in ..." | Re-trigger Greptile
Context used: