: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(data-imports): stop reporting transient billing-check DB connection blips (#75130)
Tom Owersbcc384920b1c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py b/products/warehouse_sources/backend/temporal/data_imports/row_tracking.pyindex fdc15deb707f..0d8f7642f5e1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py+++ b/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py@@ -6,6 +6,7 @@ from typing import TYPE_CHECKINGfrom django.conf import settingsfrom django.db.models import F, Q, Sum+from django.db.utils import OperationalErrorfrom dateutil import parserfrom redis import exceptions as redis_exceptions@@ -240,6 +241,12 @@ async def will_hit_billing_limit(team_id: int, source: "ExternalDataSource", log# as an error-tracking issue.await logger.awarning(f"BillingLimits: Redis error while checking billing limits, failing open: {e}")+ return False+ except OperationalError as e:+ # Same rationale as above: a dropped Postgres connection while fetching billing+ # data is a transient infra blip, and the check already fails open.+ await logger.awarning(f"BillingLimits: Database error while checking billing limits, failing open: {e}")+return Falseexcept Exception as e:await logger.adebug(f"BillingLimits: Failed with exception {e}")diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.pyindex f13415d58df3..3c8277aa715a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py@@ -9,6 +9,7 @@ from freezegun import freeze_timefrom posthog.test.base import BaseTestfrom unittest import mock+from django.db.utils import OperationalErrorfrom django.test import override_settingsfrom asgiref.sync import sync_to_async@@ -218,3 +219,25 @@ class TestRowTracking(BaseTest):assert await self._run(source, 10) is Falsemock_capture_exception.assert_not_called()++ @pytest.mark.asyncio+ async def test_row_tracking_fails_open_on_operational_error_without_capturing_exception(self):+ # A dropped Postgres connection while fetching billing data is a transient infra+ # blip, not a bug, and must fail open like any other billing-check error without+ # being reported to error tracking.+ source = await self._create_source()++ with (+ mock.patch("ee.billing.billing_manager.BillingManager.get_billing") as mock_get_billing,+ mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.row_tracking.capture_exception"+ ) as mock_capture_exception,+ ):+ mock_get_billing.side_effect = OperationalError(+ 'connection failed: connection to server at "127.0.0.1", port 5432 failed: '+ "server closed the connection unexpectedly"+ )++ assert await self._run(source, 10) is False++ mock_capture_exception.assert_not_called()