: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): always sweep abandoned staging siblings on clear (#86067)
Tom Owers68880516fa5c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_row_sink.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_row_sink.pyindex 7f072e492ae9..2af7adc58f38 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_row_sink.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_row_sink.py@@ -159,14 +159,23 @@ class PersonPropertyRowSink:wiping it would lose that sync's delta. Only prefixes older than``ABANDONED_STAGED_PREFIX_TTL`` are swept, as the backstop against a consumer that neverran.++ The two clears are independent backstops, so a failure in one (e.g. a permissions error+ deleting the own prefix) must not skip the other — the sweep always runs, and any+ own-prefix error is re-raised only afterward."""async with aget_s3_client() as s3_client:+ own_prefix_error: Exception | None = Noneif not self._is_incremental:try:await s3_client._rm(f"s3://{self._get_path_prefix()}/", recursive=True)except FileNotFoundError:pass+ except Exception as e:+ own_prefix_error = eawait self._sweep_abandoned_sibling_prefixes(s3_client)+ if own_prefix_error is not None:+ raise own_prefix_errorasync def _sweep_abandoned_sibling_prefixes(self, s3_client: Any) -> None:try:diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_row_sink_test.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_row_sink_test.pyindex b10a475953c9..95ca66c23026 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_row_sink_test.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_row_sink_test.py@@ -219,6 +219,26 @@ async def test_clear_tolerates_missing_prefixes():await sink.clear()+async def test_clear_still_sweeps_abandoned_siblings_when_own_prefix_delete_fails():+ # A permissions error (or any other non-FileNotFoundError) deleting the own prefix must not+ # skip the sibling-sweep backstop, which is an independent cleanup — otherwise abandoned sibling+ # prefixes from crashed jobs never get swept on every run where the own-prefix delete fails.+ sink = _sink()+ stale_file = f"{sink._get_binding_prefix()}/job-old/chunk_0.parquet"+ s3_client = _s3_client(+ find_result={stale_file: {"LastModified": datetime.now(UTC) - ABANDONED_STAGED_PREFIX_TTL - timedelta(days=1)}}+ )+ s3_client._rm = AsyncMock(side_effect=[PermissionError("Access Denied"), None])++ with patch(f"{_MODULE}.aget_s3_client", return_value=_FakeS3ClientCM(s3_client)):+ with pytest.raises(PermissionError):+ await sink.clear()++ removed = [call.args[0] for call in s3_client._rm.await_args_list]+ assert [f"s3://{stale_file}"] in removed # sibling sweep still ran despite the own-prefix failure++@parameterized.expand([("schema", schema_binding("schema-1")), ("saved_query", saved_query_binding("view-1"))])@pytest.mark.asyncioasync def test_stages_under_the_binding_it_was_built_for(_name, binding):