: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(data-imports): match the translated MotherDuck connection error, not the raw class (#101804)
Tom Owers7ece399bcc5f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/source.pyindex 7a2ca10e863c..feb21757694f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/source.py@@ -97,7 +97,12 @@ class MotherduckSource(SQLSource[MotherduckSourceConfig]):**self.default_non_retryable_errors(),"Catalog Error": "A database, schema, or table this source syncs no longer exists in MotherDuck, or your access token lost access to it. Check that it still exists, then resync.","Binder Error": "A column this source syncs no longer exists in MotherDuck. Reset the table so we pick up its new shape, then resync.",- "Invalid Input Error": "MotherDuck rejected the connection details. Check the database name and access token, then resync.",+ # `connect()` (motherduck.py) already translates a raw "Invalid Input Error" into this+ # user-facing text before raising `MotherDuckConnectionError`, so a connection failure's+ # message never contains the DuckDB class name to match on — only the translated text does.+ MOTHERDUCK_ERROR_CLASSES[+ "Invalid Input Error"+ ]: "MotherDuck rejected the connection details. Check the database name and access token, then resync.","Invalid MotherDuck token": None,"UNAUTHENTICATED": "Your MotherDuck token is invalid or expired. Generate a new access token and reconnect.",}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/tests/test_motherduck.py b/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/tests/test_motherduck.pyindex dda3d33f1cd3..f3df897559fc 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/tests/test_motherduck.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/tests/test_motherduck.py@@ -3,9 +3,11 @@ import osimport pytestfrom unittest.mock import MagicMock, patch+import duckdbimport pyarrow as pafrom products.warehouse_sources.backend.facade.source_config import ReleaseStatus, SourceFieldInputConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import error_message_matchesfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceInputsfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.motherduck import (MotherduckSourceConfig,@@ -13,7 +15,9 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_from products.warehouse_sources.backend.temporal.data_imports.sources.motherduck.motherduck import (DEFAULT_MOTHERDUCK_FETCH_SIZE,DUCKDB_LOCAL_CONFIG,+ MOTHERDUCK_ERROR_CLASSES,MOTHERDUCK_SYSTEM_DATABASES,+ MotherDuckConnectionError,MotherDuckImplementation,build_motherduck_connection_string,connect,@@ -529,7 +533,9 @@ class TestMotherDuck:["Catalog Error: Table with name users does not exist!","Binder Error: Referenced column email not found in FROM clause!",- "Invalid Input Error: The following options were not recognized: motherduck_token",+ # `connect()` never lets the raw "Invalid Input Error: ..." driver text reach here — it+ # always translates it to this user-facing message first, so that's what must match.+ MOTHERDUCK_ERROR_CLASSES["Invalid Input Error"],"Source column type changed",],)@@ -537,6 +543,17 @@ class TestMotherDuck:non_retryable = source.get_non_retryable_errors()assert any(pattern in error_msg for pattern in non_retryable), f"Error should be non-retryable: {error_msg}"+ def test_connection_failure_is_non_retryable_end_to_end(self, source):+ # Reproduces the real path: `connect()` wraps and translates the driver error before+ # raising, so the non-retryable match has to run against that translated text, not the+ # raw DuckDB error class. A key that only matches the raw class (as this dict used to)+ # would let a bad database name or malformed token retry indefinitely.+ with patch(_CONNECT_PATH, side_effect=duckdb.Error("Invalid Input Error: bad connection option")):+ with pytest.raises(MotherDuckConnectionError) as exc_info:+ connect("md-token", "my_db")++ assert error_message_matches(str(exc_info.value), source.get_non_retryable_errors())+def test_validate_credentials_requires_an_access_token(self, source):ok, message = source.validate_credentials(_make_config(access_token=""), team_id=1)assert ok is False