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 cdp row-staging permission gaps to error tracking (#88462)

Tom Owersecf372c7c807
diff --git a/posthog/temporal/data_modeling/activities/materialize_view.py b/posthog/temporal/data_modeling/activities/materialize_view.py
index 5791d1ce8cd1..1fc1934c738b 100644
--- a/posthog/temporal/data_modeling/activities/materialize_view.py
+++ b/posthog/temporal/data_modeling/activities/materialize_view.py
@@ -160,6 +160,19 @@ def _resolve_write_plan(saved_query: DataWarehouseSavedQuery, team_id: int) -> W
)
+def _is_s3_permission_denied(error: BaseException) -> bool:
+ """True for an S3 access-denied error on our own bucket, from either client this pipeline uses.
+
+ `s3fs`/aiobotocore (used by `CDPProducer._list_files_to_produce`) maps an AccessDenied response
+ onto the builtin `PermissionError`. pyarrow's `S3FileSystem` (used by `stage_chunk`'s parquet
+ write) doesn't set an errno for it, so the same AWS error surfaces as a plain `OSError` with the
+ AWS error code embedded in the message instead.
+ """
+ if isinstance(error, PermissionError):
+ return True
+ return isinstance(error, OSError) and "ACCESS_DENIED" in str(error)
+
+
class _CDPRowSink:
"""Stages the rows a run wrote so CDP destinations and workflows subscribed to the view can act
on them.
@@ -195,7 +208,11 @@ class _CDPRowSink:
await self._producer.stage_chunk(self._chunk, batch)
self._chunk += 1
except Exception as e:
- capture_exception(e)
+ # A missing write grant on the cdp_producer/ prefix is the same anticipated
+ # provisioning gap `_list_files_to_produce` already tolerates quietly for reads (see its
+ # `except PermissionError` branch) — not a bug worth paging on.
+ if not _is_s3_permission_denied(e):
+ capture_exception(e)
await self._logger.awarning(f"Failed to stage rows for CDP; discarding this run's staged rows: {e}")
self.enabled = False
await self.discard()
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 48c983fc9edb..379b0552e5e3 100644
--- a/posthog/temporal/tests/data_modeling/test_materialize_view_staging.py
+++ b/posthog/temporal/tests/data_modeling/test_materialize_view_staging.py
@@ -1,9 +1,10 @@
import pytest
-from unittest.mock import AsyncMock, MagicMock
+from unittest.mock import AsyncMock, MagicMock, patch
import pyarrow as pa
+from parameterized import parameterized
-from posthog.temporal.data_modeling.activities.materialize_view import _stage_person_property_batch
+from posthog.temporal.data_modeling.activities.materialize_view import _CDPRowSink, _stage_person_property_batch
pytestmark = pytest.mark.asyncio
@@ -16,6 +17,10 @@ def _batch() -> pa.RecordBatch:
return pa.RecordBatch.from_arrays([pa.array(["a"])], names=["distinct_id"])
+def _producer() -> MagicMock:
+ return MagicMock(stage_chunk=AsyncMock(), clear=AsyncMock())
+
+
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
@@ -35,3 +40,36 @@ class TestStagePersonPropertyBatch:
await _stage_person_property_batch(sink, 0, _batch(), fatal=False)
sink.logger.awarning.assert_awaited_once()
+
+
+class TestCDPRowSinkStage:
+ @parameterized.expand(
+ [
+ ("permission_error", PermissionError("Access Denied"), False),
+ (
+ "s3_access_denied_oserror",
+ OSError(
+ "When initiating multiple part upload for key 'chunk_0.parquet' in bucket "
+ "'data-warehouse': AWS Error ACCESS_DENIED during CreateMultipartUpload operation: "
+ "Access Denied (Request ID: ABCDEF)"
+ ),
+ False,
+ ),
+ ("other_error", RuntimeError("staging blew up"), True),
+ ]
+ )
+ async def test_stage_reports_only_non_permission_failures(self, _name, error, expect_capture) -> None:
+ # A missing write grant on the cdp_producer/ prefix is an anticipated provisioning gap, not a
+ # bug — reporting it would page someone for nothing actionable. Any other failure is still a
+ # real bug and must keep reaching error tracking.
+ producer = _producer()
+ producer.stage_chunk.side_effect = error
+ sink = _CDPRowSink(producer, MagicMock(awarning=AsyncMock()))
+ sink.enabled = True
+
+ with patch("posthog.temporal.data_modeling.activities.materialize_view.capture_exception") as mock_capture:
+ await sink.stage(_batch())
+
+ assert mock_capture.called is expect_capture
+ assert sink.enabled is False
+ producer.clear.assert_awaited_once()