: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 a transient app-db blip as a bug (#102812)
Tom Owersbcc5a13587f4
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.pyindex 4cc8b1e56eb6..051ff52c5dee 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.py@@ -1,9 +1,14 @@+from django.db import InterfaceError, OperationalError++import structlogimport posthoganalyticsfrom posthog.exceptions_capture import capture_exceptionfrom posthog.models.team.team import Teamfrom posthog.temporal.common.utils import retry_on_db_connection_drop+logger = structlog.get_logger(__name__)+BYTE_BOUNDED_EXTRACTION_FLAG = "warehouse-byte-bounded-extraction"@@ -21,6 +26,17 @@ def is_byte_bounded_extraction_enabled(team_id: int, source_type: str) -> bool:team = retry_on_db_connection_drop(lambda: Team.objects.only("uuid", "organization_id").get(id=team_id))except Team.DoesNotExist:return False+ except (OperationalError, InterfaceError) as e:+ # retry_on_db_connection_drop already retried once; a second OperationalError/InterfaceError+ # here is the same app-DB connectivity blip class import_data_sync._handle_import_error+ # treats as non-reportable elsewhere (pooler drop, or this worker briefly out of file+ # descriptors) - not a bug in this gate, so it shouldn't page anyone.+ logger.warning(+ "is_byte_bounded_extraction_enabled: transient app-DB error, failing closed",+ error=str(e),+ exc_info=True,+ )+ return Falseexcept Exception as e:capture_exception(e)return Falsediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.pyindex 94a8c33d30e6..3d5b3c1cf4eb 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.py@@ -1,6 +1,7 @@import pytestfrom unittest.mock import MagicMock, patch+from django.core.exceptions import ObjectDoesNotExistfrom django.db import OperationalErrorfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.byte_bounded_extraction_flag import (@@ -34,6 +35,20 @@ class TestByteBoundedExtractionFlagFailsClosed:]assert is_byte_bounded_extraction_enabled(1, "MySQL") is True+ def test_persistent_db_connection_error_fails_closed_without_reporting(self):+ # retry_on_db_connection_drop retries an OperationalError/InterfaceError once; a second+ # failure of the same kind (e.g. this worker briefly out of file descriptors) is still a+ # transient app-DB blip, not a bug in this gate, so it must not reach error tracking.+ with (+ patch(f"{_MODULE}.Team") as team_cls,+ patch(f"{_MODULE}.capture_exception") as capture_exception,+ ):+ team_cls.DoesNotExist = ObjectDoesNotExist+ team_cls.objects.only.return_value.get.side_effect = OperationalError("[Errno 24] Too many open files")+ assert is_byte_bounded_extraction_enabled(1, "Postgres") is False++ capture_exception.assert_not_called()+def test_source_type_reaches_the_flag_for_per_driver_targeting(self):with (patch(f"{_MODULE}.Team") as team_cls,