Skip to content

: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.

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.py
index 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 structlog
import posthoganalytics
from posthog.exceptions_capture import capture_exception
from posthog.models.team.team import Team
from 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 False
except Exception as e:
capture_exception(e)
return False
diff --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.py
index 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 pytest
from unittest.mock import MagicMock, patch
+from django.core.exceptions import ObjectDoesNotExist
from django.db import OperationalError
from 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,