Repository navigation
Fix/non finite float json - #1081
Open
Harsh23Kashyap wants to merge 2 commits into
Open
Harsh23Kashyap wants to merge 2 commits into
Harsh23Kashyap wants to merge 2 commits into
Conversation
Added a helper function to replace non-finite floats with None in JSON serialization.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1078.
When an event property holds a non-finite float (inf, -inf, nan), the SDK serializes batches with
json.dumps(..., cls=DatetimeSerializer)under the defaultallow_nan=True. That emits the bare tokensInfinityandNaN, which are not valid JSON, so strict-parsing ingestion and intermediaries (Go's encoding/json, most load balancers) reject the whole batch and the events are lost. posthog-js does not hit this becauseJSON.stringifyconverts non-finite numbers to null.Change:
DatetimeSerializer.encodenow routes the payload through a small recursive helper that replaces non-finite floats withNonebefore encoding, mirroringJSON.stringify. Every ingestion serialization site (sync post, capture v1, async v0 and flags bodies) goes through this encoder, so the one change covers all of them. Finite values, datetimes and other types are unchanged.Tests:
post()and asserts the request body parses under a strict JSON parser (parse_constant raises) and the values arrive as null.posthog/test/test_request.py(68 passed) andtest_capture_v1.pypass;ruff format --checkandruff checkshow no new findings on the touched files.