Skip to content

: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.

fix(warehouse_sources): skip schema discovery on undecryptable OAuth secrets (#74741)

Tom Owers9413a404c29a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/sync_new_schemas.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/sync_new_schemas.py
index 1d770d8210d3..7d9e867b129f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/sync_new_schemas.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/sync_new_schemas.py
@@ -6,6 +6,7 @@ from django.db import close_old_connections
from structlog.contextvars import bind_contextvars
from temporalio import activity
+from posthog.models.integration import UndecryptedIntegrationSecretError
from posthog.temporal.common.logger import get_logger
from products.data_warehouse.backend.facade.api import delete_discover_schemas_schedule
@@ -82,6 +83,14 @@ def sync_new_schemas_activity(inputs: SyncNewSchemasActivityInputs) -> None:
# 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.
+ #
+ # UndecryptedIntegrationSecretError is checked by type, not message, mirroring
+ # import_data_sync.py's handling: it's shared across every OAuth-based source and
+ # fails identically on every retry, so it shouldn't depend on each source listing the
+ # message in get_non_retryable_errors.
+ if isinstance(e, UndecryptedIntegrationSecretError):
+ logger.warning(f"Skipping schema discovery due to non-retryable source error: {e}")
+ return
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):
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_sync_new_schemas.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_sync_new_schemas.py
index 731f92c99f4f..9d4c1da93bcd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_sync_new_schemas.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_sync_new_schemas.py
@@ -3,6 +3,8 @@ import contextlib
import pytest
from unittest import mock
+from posthog.models.integration import UndecryptedIntegrationSecretError
+
from products.warehouse_sources.backend.temporal.data_imports.workflow_activities import sync_new_schemas as module
from products.warehouse_sources.backend.temporal.data_imports.workflow_activities.sync_new_schemas import (
SyncNewSchemasActivityInputs,
@@ -69,6 +71,20 @@ def test_get_schemas_error_handling(error_msg, non_retryable, expected_exc):
_run_activity(source_mock)
+def test_undecrypted_integration_secret_error_is_skipped():
+ # Checked by type, not message, so it must be skipped even when get_non_retryable_errors
+ # has no matching entry — otherwise discovery retries forever on an unrecoverable decryption
+ # failure and spams error tracking every cycle.
+ source_mock = mock.MagicMock()
+ source_mock.parse_config.return_value = {}
+ source_mock.get_schemas.side_effect = UndecryptedIntegrationSecretError(
+ "Integration.sensitive_config['refresh_token'] is still encrypted; the stored credentials could not be decrypted"
+ )
+ source_mock.get_non_retryable_errors.return_value = {}
+
+ _run_activity(source_mock)
+
+
def test_discovery_uses_source_pinned_api_version():
# A pinned source must discover schemas under its pin, not the default — dropping the pin
# here makes discovery reconcile under the wrong vendor version (tables vanish/duplicate).