:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(mixpanel): keep $browser_version as text in the export table (#126081)
Chris Shine59617baed35a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.pyindex ad09d97f9401..e379c901f21c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py@@ -139,6 +139,12 @@ def _flatten_event(event: dict[str, Any]) -> dict[str, Any]:properties = event.get("properties")if isinstance(properties, dict):row.update(properties)+ # Mixpanel SDKs send `$browser_version` as a number (`120`, `17.4`) or a dotted string+ # (`"130.0.0.0"`). Keeping it text gives the column one type across every batch.+ # `120.0` becomes "120" so it still casts into a table that stored the column as int64.+ browser_version = row.get("$browser_version")+ if isinstance(browser_version, (int, float)):+ row["$browser_version"] = str(int(browser_version)) if browser_version.is_integer() else str(browser_version)return rowdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.pyindex 7ffb118e1707..7d9ffdf16caa 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py@@ -312,6 +312,22 @@ class TestExportIterator:assert result.params("from_date") == ["2024-01-02"]assert [row["event"] for row in result.rows] == ["B"]+ @time_machine.travel("2024-01-01", tick=False)+ def test_browser_version_is_always_text(self) -> None:+ lines = [+ orjson.dumps({"event": "A", "properties": {"time": 1, "$browser_version": version}})+ for version in (120, 120.0, 17.4, "130.0.0.0")+ ]+ result = _driver().run(+ "export",+ [_export_answer(*lines)],+ should_use_incremental_field=True,+ db_incremental_field_last_value=date(2024, 1, 1),+ )+ assert result.raised is None+ assert [row["$browser_version"] for row in result.rows] == ["120", "120", "17.4", "130.0.0.0"]+ assert [row["time"] for row in result.rows] == [1, 1, 1, 1]+class TestExportStreamRetry:def _line(self, insert_id: str) -> bytes: