Skip to content

Fix/non finite float json - #1081

Open
Harsh23Kashyap wants to merge 2 commits into
PostHog:mainfrom
Harsh23Kashyap:fix/non-finite-float-json
Open

Harsh23Kashyap wants to merge 2 commits into
PostHog:mainfrom
Harsh23Kashyap:fix/non-finite-float-json

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown

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 default allow_nan=True. That emits the bare tokens Infinity and NaN, 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 because JSON.stringify converts non-finite numbers to null.

Change: DatetimeSerializer.encode now routes the payload through a small recursive helper that replaces non-finite floats with None before encoding, mirroring JSON.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:

  • New test sends a batch with inf, -inf and nan properties through post() and asserts the request body parses under a strict JSON parser (parse_constant raises) and the values arrive as null.
  • Control test pins that finite values round-trip unchanged.
  • The new test fails twice before the fix (strict parse rejects the body) and passes twice after it. Full posthog/test/test_request.py (68 passed) and test_capture_v1.py pass; ruff format --check and ruff check show no new findings on the touched files.

@Harsh23Kashyap
Harsh23Kashyap requested a review from a team as a code owner October 19, 2026 07:29

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event properties with inf/nan floats produce invalid JSON payloads that strict-parsing ingestion rejects

1 participant