: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(mssql): name a network cause when a connect attempt fails at setup (#108976)
Tom Owers9417f94ce0ed
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/source.pyindex 60b1e00aeab8..def2368b292d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/source.py@@ -36,16 +36,30 @@ _FIREWALL_BLOCKED_ERROR = ("try again. New rules can take a few minutes to take effect.")+# The two connect-time conditions the sync path maps below, reached through the connect form+# instead. Both need the network cause named, not just the two values: FreeTDS reports a wrong host+# or port and a server it cannot reach at all in the same words.+_SERVER_UNREACHABLE_VALIDATION_ERROR = (+ "Could not reach your SQL Server on the host and port given. Check the host and port are "+ "correct, and that PostHog's IP addresses are allowed through your firewall."+)++_CONNECTION_TIMED_OUT_ERROR = (+ "Connection timed out. Check that your server is reachable from the public internet and that "+ "PostHog's IP addresses are allowed through your firewall. For a server that can't be exposed "+ "publicly, use the SSH tunnel option."+)+MSSQLErrors = {# SQL Server error 18456 is an authentication failure (wrong username/password, or the login is# disabled), not a problem with the database field. Surface the same wording the sibling SQL# sources use and match the stable prefix, not the volatile "'<username>'." that follows it."Login failed for user": "Invalid user or password",- "Adaptive Server is unavailable or does not exist": "Could not connect to SQL server - check server host and port",+ "Adaptive Server is unavailable or does not exist": _SERVER_UNREACHABLE_VALIDATION_ERROR,# Azure SQL error 40615 — the server-level firewall rejected the connecting client IP. The full# message echoes the server name and client IP, so match the stable, distinctive phrase instead."is not allowed to access the server": _FIREWALL_BLOCKED_ERROR,- "connection timed out": "Could not connect to SQL server - check server firewall settings",+ "connection timed out": _CONNECTION_TIMED_OUT_ERROR,}_MSSQL_IMPLEMENTATION = MSSQLImplementation()diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.pyindex 2ba4b18fea0a..172a74134122 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py@@ -854,6 +854,34 @@ class TestMSSQLSourceValidateCredentials:assert error == _FIREWALL_BLOCKED_ERRORcapture.assert_not_called()+ @pytest.mark.parametrize(+ ("driver_error", "expected_guidance"),+ [+ # Real pymssql DB-Lib error 20009 for a host it cannot reach. The driver says the same+ # thing for a wrong host or port, so the copy has to cover the values and the network.+ (+ "DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is "+ "unavailable or does not exist (db.example.com)",+ ("host and port", "firewall"),+ ),+ (+ "DB-Lib error message 20003, severity 6:\nAdaptive Server connection timed out",+ ("public internet", "firewall", "SSH tunnel"),+ ),+ ],+ )+ def test_connect_failure_names_a_network_cause(self, source, mocker, driver_error, expected_guidance):+ mocker.patch.object(source, "is_database_host_valid", return_value=(True, None))+ mocker.patch.object(source, "get_schemas", side_effect=pymssql.OperationalError(driver_error))++ valid, error = source.validate_credentials(_make_config(), team_id=1)++ assert valid is False+ assert error is not None+ for fragment in expected_guidance:+ assert fragment in error+ assert "Adaptive Server" not in error+class TestIsTransientConnectionError:@pytest.mark.parametrize(