Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions posthog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,9 @@ def _enqueue(self, msg, disable_geoip, lane=None, property_allowlist=None):
k: v for k, v in msg["properties"].items() if k in property_allowlist
}

if isinstance(msg.get("properties"), dict):
msg["properties"] = {k: v for k, v in msg["properties"].items() if v is not None}

msg["distinct_id"] = stringify_id(msg.get("distinct_id", None))

msg = clean(msg)
Expand Down
17 changes: 17 additions & 0 deletions posthog/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,23 @@ def test_basic_capture(self):
assert msg["properties"]["$os"] == mock.ANY
assert msg["properties"]["$os_version"] == mock.ANY

def test_capture_sanitizes_none_properties(self):
with mock.patch("posthog.client.batch_post") as mock_post:
client = Client(FAKE_TEST_API_KEY, on_error=self.set_fail, sync_mode=True)
client.capture(
"python test event",
distinct_id="distinct_id",
properties={"valid": 123, "invalid": None}
)
self.assertFalse(self.failed)

mock_post.assert_called_once()
msg = mock_post.call_args[1]["batch"][0]

self.assertIn("valid", msg["properties"])
self.assertEqual(msg["properties"]["valid"], 123)
self.assertNotIn("invalid", msg["properties"])

def test_capture_omits_is_server_when_disabled(self):
with mock.patch("posthog.client.batch_post") as mock_post:
client = Client(
Expand Down