: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(snowflake): recognise account-not-found 404 during credential validation (#66408)
Tom Owers95ba99eddb92
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.pyindex 44dd659c963c..2b5c768d75e8 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@@ -1,6 +1,6 @@from typing import Optional, cast-from snowflake.connector.errors import DatabaseError, ForbiddenError, ProgrammingError+from snowflake.connector.errors import DatabaseError, ForbiddenError, HttpError, ProgrammingErrorfrom posthog.schema import (DataWarehouseSourceCategory,@@ -41,6 +41,11 @@ SnowflakeErrors = {"This session does not have a current database": "Database specified not found","Verify the account name is correct": "Can't find an account with the specified account ID","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+ # connector raises HttpError rather than the "Verify the account name is correct" OperationalError,+ # so it needs its own entry. The host and port in the message are volatile, so we match "404 Not Found".+ "404 Not Found": "Can't find a Snowflake account with the specified account ID. Please check your account identifier and try again.",}@@ -268,7 +273,7 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig]):try:self.get_schemas(config, team_id)- except (ProgrammingError, DatabaseError, ForbiddenError) as e:+ except (ProgrammingError, DatabaseError, ForbiddenError, HttpError) as e:error_msg = e.msg or e.raw_msg or ""for key, value in SnowflakeErrors.items():if key in error_msg: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.pyindex 78ab87928630..9cca1d4189b3 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@@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patchfrom cryptography.hazmat.backends import default_backendfrom cryptography.hazmat.primitives import serializationfrom cryptography.hazmat.primitives.asymmetric import rsa-from snowflake.connector.errors import DatabaseError+from snowflake.connector.errors import DatabaseError, HttpErrorfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SourceInputsfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.sql.predicates import (@@ -854,3 +854,48 @@ class TestSnowflakeValidateCredentials:assert ok is Falsemock_capture.assert_called_once()++ @pytest.mark.parametrize(+ "http_error, expect_capture, message_fragment",+ [+ # HttpError is a sibling of DatabaseError/ProgrammingError, so a 404 on the login-request+ # endpoint (a wrong/incomplete account id) must be recognised as a user config error and+ # surface a friendly message without capture.+ (+ HttpError(+ msg="404 Not Found: post acme.snowflakecomputing.com:443/session/v1/login-request",+ errno=290404,+ sqlstate="08001",+ send_telemetry=False,+ ),+ False,+ "account ID",+ ),+ # An unknown HttpError falls through the known-error matching and must still be captured.+ (+ HttpError(+ msg="503 Service Unavailable: post acme.snowflakecomputing.com:443/session/v1/login-request",+ errno=290503,+ sqlstate="08001",+ send_telemetry=False,+ ),+ True,+ None,+ ),+ ],+ )+ def test_http_error_routing(self, source, http_error, expect_capture, message_fragment):+ with (+ patch.object(source, "get_schemas", side_effect=http_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+ if expect_capture:+ mock_capture.assert_called_once()+ else:+ assert message is not None and message_fragment in message+ mock_capture.assert_not_called()