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): retry transient Snowflake connect blips quietly (#90693)

posthog[bot]d692281d7d3d
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py
index 92d81af195e3..55a4cfae22cc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py
@@ -61,6 +61,15 @@ _UNENCRYPTED_KEY_WITH_PASSPHRASE_MESSAGE = (
"Remove the passphrase, or paste your encrypted private key, then {action}"
)
+# Shown when `validate_credentials` hits a transient connect blip (see `get_retryable_errors`). The
+# sync path retries such a blip quietly, but interactive validation has nothing to retry
+# automatically, so it tells the user it was a brief blip and to try again rather than capturing it
+# as an unexpected bug or claiming their (correct) connection details are wrong.
+_TRANSIENT_CONNECTION_MESSAGE = (
+ "Could not reach Snowflake while checking your credentials. This is usually a brief network or "
+ "service blip rather than a configuration problem. Please try again."
+)
+
# Snowflake rejects the login (250001 / 08001) when the account enforces multi-factor auth for the
# connecting user. The server phrases this several ways, and the bare "MFA authentication is
# required" variant carries the account host and vendor codes, so it must not reach the customer
@@ -404,6 +413,13 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig]):
if key in error_msg:
return False, value
+ # A transient connect blip is not a credential or config problem, so classify it the way
+ # the sync path does (`get_retryable_errors`) and surface a "try again" message instead of
+ # capturing it as an unexpected bug. Mirrors `planetscale_mysql`'s validate_credentials.
+ for pattern in self.get_retryable_errors():
+ if pattern in error_msg:
+ return False, _TRANSIENT_CONNECTION_MESSAGE
+
capture_exception(e)
return False, "Could not connect to Snowflake. Please check all connection details are valid."
except (ValueError, TypeError) as e:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
index ba496d2f6664..33790405bdbd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
@@ -6,7 +6,7 @@ from unittest.mock import MagicMock, patch
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
-from snowflake.connector.errors import DatabaseError, HttpError
+from snowflake.connector.errors import DatabaseError, HttpError, OperationalError
from products.warehouse_sources.backend.models.external_data_source import ExternalDataSource
from products.warehouse_sources.backend.temporal.data_imports.sources.common.sql.predicates import (
@@ -1061,6 +1061,27 @@ class TestSnowflakeValidateCredentials:
assert message is not None and "multi-factor authentication" in message
mock_capture.assert_not_called()
+ def test_transient_connect_blip_returns_friendly_message_without_capture(self, source):
+ # Opening the connection failed after the connector exhausted its own login retries, raising
+ # OperationalError (a DatabaseError subclass) with the stable connect-backend phrase. The sync
+ # path retries this blip quietly, so validate must surface a "try again" message rather than
+ # capturing it and telling the user their correct connection details are wrong.
+ connect_error = OperationalError(
+ msg="250001: Could not connect to Snowflake backend after 3 attempt(s).Aborting",
+ errno=250001,
+ )
+ with (
+ patch.object(source, "get_schemas", side_effect=connect_error),
+ patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.snowflake.source.capture_exception"
+ ) as mock_capture,
+ ):
+ ok, message = source.validate_credentials(_make_config("password"), team_id=1)
+
+ assert ok is False
+ assert message is not None and "try again" in message
+ mock_capture.assert_not_called()
+
@pytest.mark.parametrize(
"raw_message",
[
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 c250d02c6a8d..8c018ce3f61a 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
@@ -7,6 +7,7 @@ from structlog.contextvars import bind_contextvars
from temporalio import activity
from posthog.models.integration import UndecryptedIntegrationSecretError
+from posthog.temporal.common.errors import NonReportableError
from posthog.temporal.common.logger import get_logger
from products.data_warehouse.backend.facade.api import delete_discover_schemas_schedule
@@ -97,6 +98,16 @@ def sync_new_schemas_activity(inputs: SyncNewSchemasActivityInputs) -> None:
if error_message_matches(error_msg, non_retryable_errors):
logger.warning(f"Skipping schema discovery due to non-retryable source error: {error_msg}")
return
+ # Retryable source errors (a transient connect blip, a self-recovering HTTP status) reach
+ # us only after the source exhausted its own retries. Re-raise as NonReportableError so the
+ # activity interceptor suppresses the error-tracking report while Temporal still retries the
+ # activity, opening a fresh connection that usually succeeds. This mirrors import_data_sync's
+ # handling of the same get_retryable_errors set. Returning here instead would skip the whole
+ # discovery pass until the next ~6h run and waste the workflow's remaining retry attempts.
+ retryable_errors = new_source.get_retryable_errors()
+ if error_message_matches(error_msg, retryable_errors):
+ logger.warning(f"Retrying schema discovery after retryable source error: {error_msg}")
+ raise NonReportableError(error_msg) from e
raise
schemas_to_sync = {s.name: s.label for s in schemas}
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 8edc212c5a76..4674f82c2b3e 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
@@ -4,6 +4,7 @@ import pytest
from unittest import mock
from posthog.models.integration import UndecryptedIntegrationSecretError
+from posthog.temporal.common.errors import NonReportableError
from products.warehouse_sources.backend.models.external_data_schema import SchemaSyncResult
from products.warehouse_sources.backend.temporal.data_imports.workflow_activities import sync_new_schemas as module
@@ -46,26 +47,29 @@ def _run_activity(source_mock, schemas_created=None, source_api_version=None):
@pytest.mark.parametrize(
- "error_msg,non_retryable,expected_exc",
+ "error_msg,non_retryable,retryable,expected_exc",
[
(
"('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})",
{"invalid_grant": None},
+ set(),
None,
),
(
"UNAVAILABLE: transient network blip",
{"invalid_grant": None},
+ set(),
"transient network blip",
),
],
ids=["non_retryable_error_is_skipped", "unknown_error_propagates"],
)
-def test_get_schemas_error_handling(error_msg, non_retryable, expected_exc):
+def test_get_schemas_error_handling(error_msg, non_retryable, 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
+ source_mock.get_retryable_errors.return_value = retryable
if expected_exc is None:
_run_activity(source_mock)
@@ -74,6 +78,21 @@ def test_get_schemas_error_handling(error_msg, non_retryable, expected_exc):
_run_activity(source_mock)
+def test_retryable_error_is_reraised_for_temporal_retry():
+ # A retryable source error (a transient connect blip) must fail the activity as NonReportableError,
+ # not complete it. NonReportableError keeps the workflow's Temporal retry (the activity interceptor
+ # re-raises it without capturing), so discovery retries within the run instead of skipping the whole
+ # ~6h pass. Mirrors import_data_sync's handling of the same get_retryable_errors set.
+ source_mock = mock.MagicMock()
+ source_mock.parse_config.return_value = {}
+ source_mock.get_schemas.side_effect = Exception("250001: Could not connect to Snowflake backend after 3 attempt(s)")
+ source_mock.get_non_retryable_errors.return_value = {}
+ source_mock.get_retryable_errors.return_value = {"Could not connect to Snowflake backend after"}
+
+ with pytest.raises(NonReportableError):
+ _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