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(snowflake): recognize invalid account identifier format (#129563)

Tom Owers4ae8f75d99d7
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 2325100f9938..a3cb433f82bb 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
@@ -66,6 +66,19 @@ _UNENCRYPTED_KEY_WITH_PASSPHRASE_MESSAGE = (
_RESOURCE_MONITOR_QUOTA_ERROR = "cannot be resumed because resource monitor"
+# Snowflake error 251001: the connector's own `_validate_account` rejects an account identifier
+# containing a character other than letters, digits, '_', '-', or '.' before any request reaches
+# Snowflake — typically the customer pasted a full URL or hostname (e.g.
+# "https://xy12345.snowflakecomputing.com") into the account id field instead of the bare
+# identifier. Nothing we send differs between attempts, so retrying can never succeed until the
+# customer corrects the field. The message is fully static (no account value embedded), so it's
+# safe to match as-is. Same `{action}` placeholder convention as `_MALFORMED_PEM_MESSAGE`.
+_INVALID_ACCOUNT_IDENTIFIER_MESSAGE = (
+ "Snowflake rejected the account identifier because it contains a character other than letters, "
+ "digits, '_', '-', or '.' (for example a slash from a pasted URL or hostname). Enter just the "
+ "account identifier (for example xy12345 or xy12345.us-east-1), 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
@@ -92,6 +105,7 @@ SnowflakeErrors = {
"Incorrect username or password was specified": "Incorrect username or password was specified",
"This session does not have a current database": "No database is available for this connection. Check that the configured database exists and that the connecting role has USAGE on it, then try again.",
"Verify the account name is correct": "Can't find an account with the specified account ID",
+ "Invalid account identifier": _INVALID_ACCOUNT_IDENTIFIER_MESSAGE.format(action="try again."),
"Multi-factor authentication is required for this account": "This Snowflake account requires multi-factor authentication enrollment. Connect with a service user that uses key-pair authentication or is exempt from MFA.",
# Snowflake error 290404: the login-request endpoint 404s because the account identifier doesn't
# resolve to a real deployment (wrong/incomplete account id, missing region/cloud segment). The
@@ -336,6 +350,7 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig], ResumableSource[Snowflak
# match the stable phrase.
"This session does not have a current database": "No database is available for this connection. Check that the configured database exists and that the connecting role has USAGE on it, then resync.",
"404 Not Found": None,
+ "Invalid account identifier": _INVALID_ACCOUNT_IDENTIFIER_MESSAGE.format(action="resync."),
"Your free trial has ended": "Your Snowflake account has been suspended or trial has ended. Please check your account status.",
"Your account is suspended due to lack of payment method": "Your Snowflake account has been suspended or trial has ended. Please check your account status.",
# Snowflake error 250001: the user account was disabled by the customer's Snowflake admin
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 af3dcafca2ac..79fec8f12848 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
@@ -1229,6 +1229,21 @@ class TestSnowflakeSourceNonRetryableErrors:
is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
assert not is_non_retryable, f"Error should remain retryable: {error_msg}"
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ "Invalid account identifier: only letters, digits, '_', '-' and '.' (as a label "
+ "separator) allowed; no slashes or backslashes",
+ # The real shape from production: the duplicated errno prefix varies, the substring is stable.
+ "251001: 251001: Invalid account identifier: only letters, digits, '_', '-' and '.' "
+ "(as a label separator) allowed; no slashes or backslashes",
+ ],
+ )
+ def test_invalid_account_identifier_is_non_retryable(self, source, error_msg):
+ non_retryable = source.get_non_retryable_errors()
+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
+ assert is_non_retryable, f"Invalid-account-identifier error should be non-retryable: {error_msg}"
+
class TestSnowflakeSourceRetryableErrors:
@pytest.fixture
@@ -1449,6 +1464,27 @@ class TestSnowflakeValidateCredentials:
assert "snowflakecomputing.com" not in message
mock_capture.assert_not_called()
+ def test_invalid_account_identifier_returns_friendly_message_without_capture(self, source):
+ # The connector's own `_validate_account` rejects the account id (e.g. a pasted URL or
+ # hostname) before any request reaches Snowflake. This is a user config error, not an
+ # unexpected failure worth capturing.
+ error = ProgrammingError(
+ msg="251001: 251001: Invalid account identifier: only letters, digits, '_', '-' and '.' "
+ "(as a label separator) allowed; no slashes or backslashes",
+ errno=251001,
+ )
+ with (
+ patch.object(source, "get_schemas", side_effect=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 "account identifier" in message
+ mock_capture.assert_not_called()
+
def test_unexpected_value_error_is_still_captured(self, source):
with (
patch.object(source, "get_schemas", side_effect=ValueError("something unexpected")),