: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-imports): stop CDP row staging failing on S3 access denied (#86807)
posthog[bot]cd24a04f80c4
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.pyindex a090afe9684b..729a49b3d413 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py@@ -135,6 +135,14 @@ class CDPProducer:return filesexcept FileNotFoundError:return []+ except PermissionError:+ # The worker may lack an s3:ListBucket grant on the cdp_producer/ prefix. Row+ # staging is best effort, so degrade to producing nothing and log a warning rather+ # than raise into error tracking.+ await self.logger.awarning(+ f"No permission to list CDP staging files at {self._get_path_prefix()}; skipping CDP row staging"+ )+ return []def _serialize_json(self, record: object, *, sort_keys: bool = False) -> bytes:try:diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.pyindex e62180a28d88..074b58e463ea 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py@@ -764,6 +764,34 @@ async def test_clear_with_no_files(mock_get_s3_client, team):mock_s3_client._rm.assert_not_called()[email protected]_db(transaction=True)+@patch("products.warehouse_sources.backend.temporal.data_imports.pipelines.core.cdp_producer.aget_s3_client")+async def test_clear_handles_permission_error_on_list(mock_get_s3_client, team):+ source = await sync_to_async(ExternalDataSource.objects.create)(+ team=team, source_type=ExternalDataSourceType.POSTGRES+ )+ table = await sync_to_async(DataWarehouseTable.objects.create)(+ team=team, name="postgres_table_1", external_data_source=source+ )+ schema = await sync_to_async(ExternalDataSchema.objects.create)(+ team=team, name="table_1", source=source, table=table+ )++ mock_s3_client = mock.AsyncMock()+ mock_s3_client._ls.side_effect = PermissionError("Access Denied")+ mock_get_s3_client.return_value.__aenter__ = mock.AsyncMock(return_value=mock_s3_client)+ mock_get_s3_client.return_value.__aexit__ = mock.AsyncMock(return_value=False)++ producer = CDPProducer.for_source(+ team_id=team.id, schema_id=str(schema.id), job_id="test_job", logger=mock.AsyncMock()+ )++ await producer.clear()++ mock_s3_client._rm.assert_not_called()++@pytest.mark.django_db(transaction=True)@pytest.mark.asyncio@patch("products.warehouse_sources.backend.temporal.data_imports.pipelines.core.cdp_producer.aget_s3_client")