: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 retrying malformed JSONPath config in REST sources (#79387)
Tom Owers22b7c1de0b79
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 fe7610559078..4d24edc4d765 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@@ -8,6 +8,7 @@ from typing import Any, NoReturn, Optionalfrom django.db import InterfaceError, OperationalErrorfrom django.db.models import Prefetch+from jsonpath_ng.exceptions import JSONPathErrorfrom requests.exceptions import HTTPErrorfrom structlog.contextvars import bind_contextvarsfrom structlog.typing import FilteringBoundLogger@@ -404,6 +405,16 @@ async def _handle_import_error(job_inputs.team_id, str(job_inputs.source_id), job_inputs.run_id, error_msg, logger, error)+ # The shared REST engine compiles data_selector/cursor_path/next_url_path/resolve-param fields+ # as JSONPath at sync time (jsonpath_utils.compile_path), not at manifest-validation time. A+ # malformed path is a fixed string, so parsing it fails identically on every retry regardless+ # of source — classify it here by type (message text varies across jsonpath_ng's several parse-+ # and lex-error shapes, so it can't be matched via get_non_retryable_errors).+ if isinstance(error, JSONPathError):+ await handle_non_retryable_error(+ job_inputs.team_id, str(job_inputs.source_id), job_inputs.run_id, error_msg, logger, error+ )+# A 404 from the shared REST engine's fallback `raise_for_status()` path means the configured# endpoint/resource doesn't exist — every retry replays the identical request against the same# dead URL. Unlike 401 (a token needing refresh, which the REST engine's own retry re-mints) ordiff --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 41a788a5a27d..31504375c963 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@@ -9,6 +9,7 @@ from unittest import mockfrom django.db import InterfaceError, OperationalError+from jsonpath_ng.exceptions import JsonPathParserErrorfrom parameterized import parameterizedfrom requests.exceptions import HTTPError@@ -435,6 +436,37 @@ async def test_schema_column_type_changed_routes_through_handler_without_source_logger.aexception.assert_not_awaited()+async def test_jsonpath_error_routes_through_handler_without_source_opt_in():+ # The shared REST engine compiles data_selector/cursor_path/resolve-param fields as JSONPath at+ # sync time, not manifest-validation time — a malformed path (e.g. a typo'd data_selector) raises+ # jsonpath_ng's JSONPathError deep in shared code. It's a fixed string, so it fails identically on+ # every retry regardless of source. It must be non-retryable by type, since jsonpath_ng's error+ # messages vary across parse/lex failure shapes and can't be matched via get_non_retryable_errors.+ error = JsonPathParserError("Parse error at 1:0 near token . (.)")+ 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()++@pytest.mark.asyncioasync 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),