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-modeling): stop reporting self-healing db drops from property staging (#109429)

Tom Owersbad532581902
diff --git a/posthog/temporal/data_modeling/activities/materialize_view.py b/posthog/temporal/data_modeling/activities/materialize_view.py
index 7c1d5342f2da..de2b027cbd92 100644
--- a/posthog/temporal/data_modeling/activities/materialize_view.py
+++ b/posthog/temporal/data_modeling/activities/materialize_view.py
@@ -36,6 +36,7 @@ from posthog.temporal.common.clickhouse import (
ClickHouseError,
get_client as get_clickhouse_client,
)
+from posthog.temporal.common.db_errors import is_transient_db_error
from posthog.temporal.common.errors import NonReportableError
from posthog.temporal.common.heartbeat import Heartbeater
from posthog.temporal.common.logger import get_logger
@@ -874,7 +875,8 @@ async def _build_person_property_sink(
return sink if await sink.should_run() else None
except Exception as e:
await logger.awarning(f"Could not resolve person-property staging for this view: {e}")
- capture_exception(e)
+ if not is_transient_db_error(e):
+ capture_exception(e)
return None
@@ -891,7 +893,8 @@ async def _account_property_sync_enabled(
return await sink.should_run()
except Exception as error:
await logger.awarning(f"Could not resolve account-property staging for this view: {error}")
- capture_exception(error)
+ if not is_transient_db_error(error):
+ capture_exception(error)
return False
diff --git a/posthog/temporal/tests/data_modeling/test_materialize_view_staging.py b/posthog/temporal/tests/data_modeling/test_materialize_view_staging.py
index 379b0552e5e3..7d53ea91437b 100644
--- a/posthog/temporal/tests/data_modeling/test_materialize_view_staging.py
+++ b/posthog/temporal/tests/data_modeling/test_materialize_view_staging.py
@@ -1,10 +1,19 @@
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
+from django.db import OperationalError
+
import pyarrow as pa
from parameterized import parameterized
-from posthog.temporal.data_modeling.activities.materialize_view import _CDPRowSink, _stage_person_property_batch
+from posthog.temporal.data_modeling.activities.materialize_view import (
+ AccountPropertyRowSink,
+ PersonPropertyRowSink,
+ _account_property_sync_enabled,
+ _build_person_property_sink,
+ _CDPRowSink,
+ _stage_person_property_batch,
+)
pytestmark = pytest.mark.asyncio
@@ -21,6 +30,10 @@ def _producer() -> MagicMock:
return MagicMock(stage_chunk=AsyncMock(), clear=AsyncMock())
+def _matview_objects() -> MagicMock:
+ return MagicMock(team=MagicMock(pk=1), saved_query=MagicMock(id="01978e6b-0000-7000-8000-000000000000"))
+
+
class TestStagePersonPropertyBatch:
async def test_incremental_staging_failure_fails_the_run(self) -> None:
# Swallowing this would let the watermark advance past rows that never reached staging, and an
@@ -73,3 +86,46 @@ class TestCDPRowSinkStage:
assert mock_capture.called is expect_capture
assert sink.enabled is False
producer.clear.assert_awaited_once()
+
+
+class TestPropertySinkResolutionReportsOnlyNonTransientFailures:
+ @parameterized.expand(
+ [
+ ("transient_connection_drop", OperationalError("server closed the connection unexpectedly"), False),
+ ("other_error", RuntimeError("boom"), True),
+ ]
+ )
+ async def test_build_person_property_sink(self, _name, error, expect_capture) -> None:
+ # A pgbouncer connection recycle while resolving the person-property projection must not fail
+ # the materialization (should_run's failure is already swallowed) or page anyone — it clears on
+ # its own. A non-transient failure is a real bug and must keep reaching error tracking.
+ objects = _matview_objects()
+ logger = MagicMock(awarning=AsyncMock())
+
+ with (
+ patch.object(PersonPropertyRowSink, "should_run", AsyncMock(side_effect=error)),
+ patch("posthog.temporal.data_modeling.activities.materialize_view.capture_exception") as mock_capture,
+ ):
+ result = await _build_person_property_sink(objects, "job-1", logger, incremental=False)
+
+ assert result is None
+ assert mock_capture.called is expect_capture
+
+ @parameterized.expand(
+ [
+ ("transient_connection_drop", OperationalError("server closed the connection unexpectedly"), False),
+ ("other_error", RuntimeError("boom"), True),
+ ]
+ )
+ async def test_account_property_sync_enabled(self, _name, error, expect_capture) -> None:
+ objects = _matview_objects()
+ logger = MagicMock(awarning=AsyncMock())
+
+ with (
+ patch.object(AccountPropertyRowSink, "should_run", AsyncMock(side_effect=error)),
+ patch("posthog.temporal.data_modeling.activities.materialize_view.capture_exception") as mock_capture,
+ ):
+ result = await _account_property_sync_enabled(objects, "job-1", logger)
+
+ assert result is False
+ assert mock_capture.called is expect_capture