: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 shared REST client rate-limit retries minting error-tracking noise (#74133)
Tom Owers5bae503a9fd8
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 b0f6ff2210a2..f9466de0cba0 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@@ -49,6 +49,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.basfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.job_context import bind_job_contextfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client import (RESTClientNonRetryableError,+ RESTClientRetryableError,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.sql.predicates import (@@ -330,7 +331,8 @@ async def _handle_import_error(Errors the source classifies as retryable (rate limits, transient 5xx) reach us only afterthe source's own retries are exhausted. Temporal retries the whole activity and the error istransient and self-recovering, so we log at ``warning`` rather than ``exception`` to keep- this benign, recoverable failure out of error tracking.+ this benign, recoverable failure out of error tracking. ``RESTClientRetryableError`` gets the+ same treatment by type, since every REST-based source hits that condition already.Everything else is logged as an exception and re-raised so Temporal retries it as usual."""@@ -355,6 +357,17 @@ async def _handle_import_error(job_inputs.team_id, str(job_inputs.source_id), job_inputs.run_id, error_msg, logger, error)+ # RESTClientRetryableError only escapes the shared REST engine's own tenacity retry loop once+ # that budget (rate limits, transient 5xx, connection resets/timeouts) is exhausted — the same+ # "reaches us only after internal retries exhaust" contract as get_retryable_errors below.+ # Honor it by type so every REST-based source gets this benign, self-recovering failure logged+ # as a warning, rather than depending on each source separately listing "HTTP 429"/"HTTP 5xx"+ # in get_retryable_errors.+ if isinstance(error, RESTClientRetryableError):+ await logger.awarning(error_msg)+ await logger.adebug("REST client exhausted its retries - re-raising for Temporal retry")+ raise error+non_retryable_errors = source_cls.get_non_retryable_errors()if any(match in error_msg for match in non_retryable_errors):await handle_non_retryable_error(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 690005078d46..1dbcda1f6edb 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@@ -11,6 +11,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipelinefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.base import SimpleSourcefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client import (RESTClientNonRetryableError,+ RESTClientRetryableError,)from products.warehouse_sources.backend.temporal.data_imports.util import NonRetryableExceptionfrom products.warehouse_sources.backend.temporal.data_imports.workflow_activities import import_data_sync as module@@ -189,6 +190,31 @@ async def test_rest_client_non_retryable_error_routes_through_handler_without_sologger.aexception.assert_not_awaited()+async def test_rest_client_retryable_error_logged_as_warning_without_source_opt_in():+ # RESTClientRetryableError only escapes the shared REST engine's tenacity retry loop once its+ # own attempts (rate limits, transient 5xx, connection resets/timeouts) are exhausted. It must+ # be honored by type even when the source's get_retryable_errors doesn't list the message, so+ # every REST-based source gets this benign, self-recovering failure logged as a warning instead+ # of minting error-tracking noise.+ error = RESTClientRetryableError("HTTP 429 for https://api.example.com/v3/orders/")+ 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):+ with pytest.raises(RESTClientRetryableError):+ await module._handle_import_error(mock.MagicMock(), logger, error)++ logger.awarning.assert_awaited_once()+ logger.aexception.assert_not_awaited()++@pytest.mark.asyncioasync def test_schema_column_type_changed_routes_through_handler_without_source_opt_in():# SchemaColumnTypeChangedException is raised in shared pipeline code when incoming data can't be