: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-warehouse): skip schema discovery on non-retryable source errors (#61608)
Tom Owers578fda0543ad
diff --git a/posthog/temporal/data_imports/workflow_activities/sync_new_schemas.py b/posthog/temporal/data_imports/workflow_activities/sync_new_schemas.pyindex 4f19e4762066..e4bbdcc22a09 100644--- a/posthog/temporal/data_imports/workflow_activities/sync_new_schemas.py+++ b/posthog/temporal/data_imports/workflow_activities/sync_new_schemas.py@@ -58,7 +58,21 @@ def sync_new_schemas_activity(inputs: SyncNewSchemasActivityInputs) -> None:new_source = SourceRegistry.get_source(source_type_enum)config = new_source.parse_config(source.job_inputs)- schemas = new_source.get_schemas(config, inputs.team_id)+ try:+ schemas = new_source.get_schemas(config, inputs.team_id)+ except Exception as e:+ # Schema discovery is best-effort and runs on its own ~6h cadence. If the source's+ # credentials are broken (expired/revoked tokens, permission denied, deleted account,+ # etc.) discovery will keep failing until the user reconnects — there is nothing to+ # retry here, and the per-schema sync path surfaces and disables the source on the+ # same error. Skip quietly on known non-retryable source errors rather than spamming+ # retries and error tracking on every discovery run. Other errors still propagate.+ error_msg = str(e)+ non_retryable_errors = new_source.get_non_retryable_errors()+ if any(pattern in error_msg for pattern in non_retryable_errors):+ logger.warning(f"Skipping schema discovery due to non-retryable source error: {error_msg}")+ return+ raiseschemas_to_sync = {s.name: s.label for s in schemas}else:diff --git a/posthog/temporal/data_imports/workflow_activities/tests/test_sync_new_schemas.py b/posthog/temporal/data_imports/workflow_activities/tests/test_sync_new_schemas.pynew file mode 100644index 000000000000..1af91589fda5--- /dev/null+++ b/posthog/temporal/data_imports/workflow_activities/tests/test_sync_new_schemas.py@@ -0,0 +1,60 @@+import pytest+from unittest import mock++from posthog.temporal.data_imports.workflow_activities import sync_new_schemas as module+from posthog.temporal.data_imports.workflow_activities.sync_new_schemas import (+ SyncNewSchemasActivityInputs,+ sync_new_schemas_activity,+)+++def _patch_common(source_mock):+ """Patch DB + registry so the activity runs without a database or real source."""+ existing_source = mock.MagicMock(source_type="GoogleAds", job_inputs={"k": "v"}, deleted=False)+ objects = mock.MagicMock()+ objects.filter.return_value.exclude.return_value.exists.return_value = True+ objects.get.return_value = existing_source++ return (+ mock.patch.object(module, "close_old_connections"),+ mock.patch.object(module.ExternalDataSource, "objects", objects),+ mock.patch.object(module, "ExternalDataSourceType", return_value="GoogleAds"),+ mock.patch.object(module.SourceRegistry, "is_registered", return_value=True),+ mock.patch.object(module.SourceRegistry, "get_source", return_value=source_mock),+ mock.patch.object(module, "sync_old_schemas_with_new_schemas", return_value=([], [])),+ )+++def _run_activity(source_mock):+ patches = _patch_common(source_mock)+ with patches[0], patches[1], patches[2], patches[3], patches[4], patches[5]:+ sync_new_schemas_activity(SyncNewSchemasActivityInputs(source_id="src", team_id=1))+++ "error_msg,non_retryable,expected_exc",+ [+ (+ "('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})",+ {"invalid_grant": None},+ None,+ ),+ (+ "UNAVAILABLE: transient network blip",+ {"invalid_grant": None},+ "transient network blip",+ ),+ ],+ ids=["non_retryable_error_is_skipped", "unknown_error_propagates"],+)+def test_get_schemas_error_handling(error_msg, non_retryable, expected_exc):+ source_mock = mock.MagicMock()+ source_mock.parse_config.return_value = {}+ source_mock.get_schemas.side_effect = Exception(error_msg)+ source_mock.get_non_retryable_errors.return_value = non_retryable++ if expected_exc is None:+ _run_activity(source_mock)+ else:+ with pytest.raises(Exception, match=expected_exc):+ _run_activity(source_mock)