: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): honor shared non-retryable errors in import handler (#75034)
Tom Owers090663747477
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.pyindex d033de1fbd70..ba2c29905923 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py@@ -378,7 +378,16 @@ async def _handle_import_error(await logger.adebug("REST client exhausted its retries - re-raising for Temporal retry")raise error- non_retryable_errors = source_cls.get_non_retryable_errors()+ # Cross-source non-retryable errors (missing primary key on an incremental table, bad SSH tunnel+ # auth, a widened column type) are raised from shared pipeline code, not any one source. The+ # finalization activity already consults this shared dict; this in-activity handler decides whether+ # to re-raise for a full retry, so without it a shared config error retries the activity's whole+ # budget and reports on every attempt. Merge it in — source-specific entries win on overlap.+ from products.warehouse_sources.backend.temporal.data_imports.external_data_job import ( # noqa: PLC0415 — deferred to break the external_data_job -> import_data_sync import cycle+ Any_Source_Errors,+ )++ non_retryable_errors = {**Any_Source_Errors, **source_cls.get_non_retryable_errors()}if any(match in error_msg for match in non_retryable_errors):await handle_non_retryable_error(job_inputs.team_id, str(job_inputs.source_id), job_inputs.run_id, error_msg, logger, errordiff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.pyindex 2ee408774c41..a04c2a182f4e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py@@ -257,6 +257,37 @@ async def test_schema_column_type_changed_routes_through_handler_without_source_logger.aexception.assert_not_awaited()+async def test_shared_non_retryable_error_routes_through_handler_without_source_opt_in():+ # "Primary key required for incremental syncs" is raised in shared pipeline code (delta merge),+ # not any one source, and lives in the shared Any_Source_Errors dict. It must be non-retryable in+ # this in-activity handler for every source, not just those that duplicate the message into their+ # own get_non_retryable_errors — otherwise a keyless incremental table retries the activity's whole+ # budget and reports on every attempt.+ error = Exception("Primary key required for incremental syncs")+ source = mock.MagicMock(spec=SimpleSource)+ source.get_non_retryable_errors.return_value = {}+ source.get_retryable_errors.return_value = set()++ logger = mock.MagicMock()+ logger.awarning = mock.AsyncMock()+ logger.aexception = mock.AsyncMock()+ logger.adebug = mock.AsyncMock()++ with (+ mock.patch.object(module.SourceRegistry, "get_source", return_value=source),+ mock.patch.object(module, "handle_non_retryable_error", autospec=True) as handle_mock,+ ):+ handle_mock.side_effect = NonRetryableException()+ with pytest.raises(NonRetryableException):+ await module._handle_import_error(mock.MagicMock(), logger, error)++ handle_mock.assert_awaited_once()+ assert handle_mock.await_args is not None+ assert handle_mock.await_args.args[5] is error+ logger.aexception.assert_not_awaited()++def _incremental_schema(*, is_incremental: bool, lookback_seconds: int | None) -> mock.MagicMock:schema = mock.MagicMock()schema.should_use_incremental_field = True