: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): retry transient app-DB blips during import setup (#87038)
Tom Owers48ffa94e6858
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 970bc17ea1bc..fc3d69b0d27d 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@@ -231,7 +231,20 @@ async def import_data_activity_sync(inputs: ImportDataActivityInputs) -> Pipelin# zombie predecessor stands down (its heartbeat timed out, but it may still be running).attempt=current_activity_attempt(),):- return await _import_data_with_reporting(inputs, logger)+ try:+ return await _import_data_with_reporting(inputs, logger)+ except (OperationalError, InterfaceError, PostHogInternalDatabaseError) as e:+ # The setup phase (resolving the job/schema/source rows for this run) reads PostHog's+ # own app DB through the Django ORM before the source's error handling takes over. A+ # transient connection-pool blip there — a PgBouncer server_login_retry cooldown, the+ # primary briefly in recovery — raises this exception type, which can only mean our own+ # infra, never the customer's source (every source talks to a customer database over a+ # raw driver connection, not the ORM). Re-raise as NonReportableError so Temporal+ # retries the whole activity and it self-heals, rather than failing the sync with the+ # raw driver string as latest_error. _handle_import_error already classifies these types+ # this way once the run is under way; this covers the setup calls that run before it.+ await logger.awarning(str(e))+ raise NonReportableError(str(e)) from easync def _import_data_with_reporting(inputs: ImportDataActivityInputs, logger: FilteringBoundLogger) -> PipelineResult:diff --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 6c2665c921b6..36170245a5f4 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@@ -200,6 +200,29 @@ async def test_schema_deleted_mid_sync_routes_through_handler():source.parse_config.assert_not_called()+async def test_transient_app_db_error_in_setup_is_retryable_not_raw():+ # The setup phase resolves this run's job/schema/source rows over the Django ORM (our own app+ # DB). A transient connection-pool blip there — e.g. a PgBouncer server_login_retry cooldown —+ # raises a Django OperationalError before the source's error handling runs. It's our infra, not+ # the customer's source, so it must be re-raised as NonReportableError (Temporal retries the+ # whole activity and it self-heals) rather than escaping raw and being stored verbatim as+ # latest_error while minting error-tracking noise.+ error = OperationalError("server login has been failing, cached error: (server_login_retry)")+ source = mock.MagicMock(spec=SimpleSource)++ with (+ _patched_activity(source) as handle_mock,+ mock.patch.object(module, "_get_external_data_job", new=mock.AsyncMock(side_effect=error)),+ ):+ with pytest.raises(NonReportableError) as exc_info:+ await import_data_activity_sync(_inputs())++ assert exc_info.value.__cause__ is error+ handle_mock.assert_not_awaited()+ source.source_for_pipeline.assert_not_called()++@pytest.mark.asyncioasync def test_source_classified_retryable_error_logged_as_warning_not_exception():# A rate-limit / transient error the source retries internally reaches _handle_import_error only