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): don't report a dropped app-db connection during repartition detection (#80145)

Tom Owers18f7e1dc865b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py
index 04d3a496e5f1..a682e2cf5c46 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py
@@ -32,10 +32,10 @@ from posthog.temporal.common.utils import retry_on_db_connection_drop
from products.warehouse_sources.backend.models.external_data_job import ExternalDataJob
from products.warehouse_sources.backend.models.external_data_schema import ExternalDataSchema
-from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.table import (
- DeltaTableRef,
- is_transient_object_store_error,
+from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.errors import (
+ is_transient_maintenance_error,
)
+from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.table import DeltaTableRef
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.repartition import (
RepartitionBudgetExceededError,
RepartitionSupersededError,
@@ -197,10 +197,12 @@ def _maybe_flag_pre_extraction(
except Exception as e:
# Detection is best-effort; a failure here must not block the sync. `get_delta_table` re-raises
# transient object-store blips (S3/credential-provider timeouts) rather than swallowing them —
- # see its own docstring — so this is the layer that must apply is_transient_object_store_error
- # before reporting, same as the other best-effort call sites around this table.
- if is_transient_object_store_error(e):
- logger.warning("repartition: pre-extraction detection failed with a transient object-store error")
+ # see its own docstring — and resolving `job.folder_path()` on a pooled app-DB connection can
+ # raise OperationalError/InterfaceError the same way. `is_transient_maintenance_error` covers
+ # both, so this is the layer that must apply it before reporting, same as the other best-effort
+ # call sites around this table.
+ if is_transient_maintenance_error(e):
+ logger.warning("repartition: pre-extraction detection failed with a transient infra error")
else:
logger.warning("repartition: pre-extraction detection failed", exc_info=True)
capture_exception(e)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_repartition_table.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_repartition_table.py
index 593b93d0bfd3..22239d4f323f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_repartition_table.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_repartition_table.py
@@ -5,6 +5,8 @@ import contextvars
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
+from django.db import InterfaceError, OperationalError
+
from parameterized import parameterized
from posthog.exceptions_capture import ambient_exception_properties
@@ -324,6 +326,28 @@ class TestMaybeFlagPreExtraction:
assert result is None
mock_capture.assert_not_called()
+ @parameterized.expand(
+ [
+ ("operational_error", OperationalError("consuming input failed: server closed the connection")),
+ ("interface_error", InterfaceError("connection already closed")),
+ ]
+ )
+ @patch(f"{MODULE}.capture_exception")
+ def test_transient_db_connection_drop_is_not_reported(
+ self, _name: str, error: Exception, mock_capture: MagicMock
+ ) -> None:
+ # `get_delta_table` resolves `job.folder_path()` on a pooled app-DB connection (see
+ # `DeltaTableRef._get_delta_table_uri`), which can raise these on a stale pooled connection —
+ # not the object-store errors `is_transient_object_store_error` alone would catch.
+ schema = _schema(name="stripe_charge", s3_folder_name=None)
+ helper = MagicMock()
+ helper.get_delta_table = AsyncMock(side_effect=error)
+
+ result = _maybe_flag_pre_extraction(schema, MagicMock(), helper, MagicMock(), enabled=True)
+
+ assert result is None
+ mock_capture.assert_not_called()
+
@patch(f"{MODULE}.capture_exception")
def test_non_transient_error_is_still_reported(self, mock_capture: MagicMock) -> None:
schema = _schema(name="stripe_charge", s3_folder_name=None)