From 5a74a0848fc6db0dd931bdfd8175c00c16849ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Wed, 30 Oct 2024 16:03:18 +0100 Subject: [PATCH] fix(batch-exports): Set default function when JSON dumping --- posthog/temporal/batch_exports/temporary_file.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/posthog/temporal/batch_exports/temporary_file.py b/posthog/temporal/batch_exports/temporary_file.py index 19973d3d84617..d26db8b976171 100644 --- a/posthog/temporal/batch_exports/temporary_file.py +++ b/posthog/temporal/batch_exports/temporary_file.py @@ -482,7 +482,7 @@ def write_dict(self, d: dict[str, typing.Any]) -> int: # We tried, fallback to the slower but more permissive stdlib # json. logger.exception("PostHog $web_vitals event didn't match expected structure") - dumped = json.dumps(d).encode("utf-8") + dumped = json.dumps(d, default=str).encode("utf-8") n = self.batch_export_file.write(dumped + b"\n") else: dumped = orjson.dumps(d, default=str) @@ -492,7 +492,7 @@ def write_dict(self, d: dict[str, typing.Any]) -> int: # In this case, we fallback to the slower but more permissive stdlib # json. logger.exception("Orjson detected a deeply nested dict: %s", d) - dumped = json.dumps(d).encode("utf-8") + dumped = json.dumps(d, default=str).encode("utf-8") n = self.batch_export_file.write(dumped + b"\n") else: # Orjson is very strict about invalid unicode. This slow path protects us