: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(revenue-analytics): don't capture transient db drops in view sync (#67589)
posthog[bot]9fb488c1bc94
diff --git a/products/revenue_analytics/backend/test/test_warehouse_view_sync.py b/products/revenue_analytics/backend/test/test_warehouse_view_sync.pynew file mode 100644index 000000000000..e6d27e523bdc--- /dev/null+++ b/products/revenue_analytics/backend/test/test_warehouse_view_sync.py@@ -0,0 +1,43 @@+from unittest.mock import MagicMock, patch++from django.db import InterfaceError, OperationalError++from parameterized import parameterized++from products.revenue_analytics.backend.views.orchestrator import SUPPORTED_SOURCES+from products.revenue_analytics.backend.warehouse_view_sync import sync_revenue_analytics_views+++def _make_schema_and_source() -> tuple[MagicMock, MagicMock]:+ schema = MagicMock()+ schema.team_id = 1+ source = MagicMock()+ source.revenue_analytics_config_safe.enabled = True+ source.source_type = SUPPORTED_SOURCES[0]+ return schema, source+++class TestWarehouseViewSync:+ @parameterized.expand([("operational", OperationalError), ("interface", InterfaceError)])+ @patch("products.revenue_analytics.backend.warehouse_view_sync.capture_exception")+ @patch("products.revenue_analytics.backend.warehouse_view_sync.DataWarehouseManagedViewSet")+ def test_transient_connection_error_is_not_captured(+ self, _name: str, error_cls: type[Exception], mock_viewset: MagicMock, mock_capture: MagicMock+ ) -> None:+ mock_viewset.objects.filter.return_value.first.side_effect = error_cls("server closed the connection")+ schema, source = _make_schema_and_source()++ sync_revenue_analytics_views(schema, source)++ mock_capture.assert_not_called()++ @patch("products.revenue_analytics.backend.warehouse_view_sync.capture_exception")+ @patch("products.revenue_analytics.backend.warehouse_view_sync.DataWarehouseManagedViewSet")+ def test_unexpected_error_is_captured(self, mock_viewset: MagicMock, mock_capture: MagicMock) -> None:+ error = ValueError("something actually broke")+ mock_viewset.objects.filter.return_value.first.side_effect = error+ schema, source = _make_schema_and_source()++ sync_revenue_analytics_views(schema, source)++ mock_capture.assert_called_once_with(error)diff --git a/products/revenue_analytics/backend/warehouse_view_sync.py b/products/revenue_analytics/backend/warehouse_view_sync.pyindex 66d135d30a1c..f9e870b2a203 100644--- a/products/revenue_analytics/backend/warehouse_view_sync.py+++ b/products/revenue_analytics/backend/warehouse_view_sync.py@@ -9,6 +9,8 @@ from __future__ import annotationsfrom typing import TYPE_CHECKING+from django.db import InterfaceError, OperationalError+import structlogfrom posthog.exceptions_capture import capture_exception@@ -56,6 +58,18 @@ def sync_revenue_analytics_views(schema: ExternalDataSchema, source: ExternalDatteam_id=schema.team_id,source_id=str(source.id),)+ except (OperationalError, InterfaceError) as e:+ # Transient DB connection drop (the pgbouncer pooler recycling / closing a stale+ # connection mid-query). This isn't a real failure of the view sync: the data-import+ # pipeline retries the post-load hook on a fresh connection. Log for visibility but+ # don't capture_exception — a momentary pooler blip shouldn't spin up an error+ # tracking issue.+ logger.warning(+ "sync_revenue_analytics_views_transient_db_error",+ team_id=schema.team_id,+ source_id=str(source.id),+ error=str(e),+ )except Exception as e:logger.exception("sync_revenue_analytics_views_failed",