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): classify denied s3 writes in the v3 pipeline writer (#112360)

Tom Owers0939c84717dc
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.py
index d3bdab851ae5..f968622e9890 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.py
@@ -9,6 +9,9 @@ import pyarrow as pa
import botocore.exceptions
from parameterized import parameterized
+from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.ops import (
+ ObjectStorePermissionDeniedError,
+)
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.s3.writer import (
S3BatchWriter,
_write_parquet_to_s3,
@@ -150,6 +153,35 @@ class TestBatchByteSize:
assert result.byte_size == expected
+class TestWriteBatchPermissionDenied:
+ @patch(
+ "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.s3.writer._write_parquet_to_s3"
+ )
+ @patch("products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.s3.writer.ensure_bucket")
+ @patch("products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.s3.writer.get_s3_client")
+ def test_write_batch_wraps_access_denied_instead_of_raising_raw_error(
+ self,
+ _mock_get_s3_client,
+ _mock_ensure_bucket,
+ mock_write,
+ ) -> None:
+ # The data warehouse bucket is PostHog's own, so an AccessDenied writing to it used to
+ # escape write_batch as a raw PermissionError: it read to the customer as if their source
+ # credentials were bad, and error tracking grouped a fresh issue per retry instead of one
+ # stable title.
+ mock_write.side_effect = PermissionError("Access Denied")
+
+ job = MagicMock()
+ job.team_id = 1
+ job.created_at = datetime(2026, 8, 5, tzinfo=UTC)
+ writer = S3BatchWriter(MagicMock(), job, schema_id="schema-1", run_uuid="run-1")
+
+ with pytest.raises(ObjectStorePermissionDeniedError) as raised:
+ writer.write_batch(pa.table({"id": [1]}), 0)
+
+ assert raised.value.__cause__ is mock_write.side_effect
+
+
class TestSchemaAccumulation:
@parameterized.expand(
[
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/writer.py
index 49070a34e28e..76a9f52cc4cd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/writer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/writer.py
@@ -16,6 +16,11 @@ from products.warehouse_sources.backend.models.external_data_job import External
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.arrow_utils import (
unify_schemas_with_text_fallback,
)
+from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.ops import (
+ OBJECT_STORE_PERMISSION_DENIED_MESSAGE,
+ ObjectStorePermissionDeniedError,
+ is_object_store_permission_denied,
+)
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.metrics import (
get_s3_write_duration_metric,
get_s3_write_errors_metric,
@@ -163,6 +168,12 @@ class S3BatchWriter:
except Exception as e:
if activity.in_activity():
get_s3_write_errors_metric(type(e).__name__).add(1)
+ # The data warehouse bucket is PostHog's own, so a refusal here is never the
+ # customer's source or credentials. Raise the typed error so the run's error text
+ # doesn't read like a problem with their data, and error tracking groups every
+ # occurrence on one title instead of the raw per-key s3fs message.
+ if is_object_store_permission_denied(e):
+ raise ObjectStorePermissionDeniedError(OBJECT_STORE_PERMISSION_DENIED_MESSAGE) from e
raise
write_duration = time.perf_counter() - write_start
@@ -207,8 +218,13 @@ class S3BatchWriter:
self._logger.debug(f"Writing schema to {schema_path}")
- with self._s3.open(s3_path_without_protocol, "w") as f:
- json.dump(schema_dict, f, indent=2)
+ try:
+ with self._s3.open(s3_path_without_protocol, "w") as f:
+ json.dump(schema_dict, f, indent=2)
+ except Exception as e:
+ if is_object_store_permission_denied(e):
+ raise ObjectStorePermissionDeniedError(OBJECT_STORE_PERMISSION_DENIED_MESSAGE) from e
+ raise
self._logger.debug(f"Schema written successfully", s3_path=schema_path)