: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): treat dropped-table metadata lookup as non-retryable (#68305)
Tom Owersdbf2530cea8b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.pyindex 7621e913d083..456bfab7c88c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py@@ -97,6 +97,16 @@ _MAX_DEADLOCK_ATTEMPTS = 5# `MSSQLSource.get_non_retryable_errors`) — same gateway-config class as a wrapped tunnel failure._SSH_HANDSHAKE_EOF_ERROR = "SSH gateway closed the connection during the SSH handshake"+# Raised by `get_table_metadata` when INFORMATION_SCHEMA.COLUMNS returns no rows for a table we+# were asked to sync — the table was dropped or renamed at the source after schema discovery (or+# its schema/name no longer matches under the server's collation). Unlike a live SELECT against a+# missing object (SQL Server error 208, "Invalid object name"), this metadata lookup returns an+# empty result set rather than erroring, so this guard fires first. Retrying replays the identical+# lookup and gets the same empty result, so it's classified non-retryable (see+# `MSSQLSource.get_non_retryable_errors`). Kept as a stable prefix so the match stays clear of the+# volatile schema/table name that follows it.+_TABLE_NOT_FOUND_ERROR = "Table not found when reading column metadata"+def _is_transient_connection_error(error: BaseException) -> bool:"""True for a mid-stream TDS connection death that a fresh connection recovers from."""@@ -680,7 +690,7 @@ class MSSQLImplementation(SQLSourceImplementation[MSSQLSourceConfig, pymssql.Con)if not columns:- raise ValueError(f"Table {table_name} not found")+ raise ValueError(f"{_TABLE_NOT_FOUND_ERROR}: {schema}.{table_name}")return Table(name=table_name,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 43f5f6d61ca9..bda9296e57cd 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@@ -24,6 +24,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.sqlfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs import MSSQLSourceConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.mssql.mssql import (_SSH_HANDSHAKE_EOF_ERROR,+ _TABLE_NOT_FOUND_ERROR,MSSQLImplementation,retry_on_transient_connection_error,)@@ -111,6 +112,13 @@ class MSSQLSource(SQLSource[MSSQLSourceConfig], SSHTunnelMixin, ValidateDatabase# existing column in place, so retrying won't help — the table must be reset and# fully re-synced to adopt the new type."Source column type changed": "A column's type changed in your source database (for example an integer column was widened to bigint) and no longer fits the type we stored. We can't widen an existing column in place — please reset and fully re-sync this table to adopt the new type.",+ # Raised by `get_table_metadata` when INFORMATION_SCHEMA.COLUMNS returns no columns for a+ # table we were asked to sync — the table was dropped or renamed at the source after+ # schema discovery. This is the metadata-lookup counterpart of "Invalid object name"+ # (SQL Server error 208): the lookup returns an empty result set rather than erroring, so+ # our own guard fires before the SELECT. The table is gone from the source, so retrying+ # replays the identical empty lookup. Match the stable prefix, not the schema/table name.+ _TABLE_NOT_FOUND_ERROR: "One of the tables you're syncing no longer exists in your SQL Server — it was likely dropped or renamed after it was first discovered. Remove it from the sync or restore it at the source, then re-enable the sync.",}def get_schemas(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 88cff7618ac5..f223c1f980d0 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@@ -651,6 +651,16 @@ class TestMSSQLSourceNonRetryableErrors:non_retryable = MSSQLSource().get_non_retryable_errors()assert any(pattern in error_msg for pattern in non_retryable.keys()), error_msg+ def test_table_not_found_is_non_retryable(self, impl, cursor):+ # Drive the real raise site so the message and the rule can't drift apart: a table dropped+ # after schema discovery yields no columns from INFORMATION_SCHEMA and must stop retrying.+ cursor.__iter__.return_value = iter([])+ with pytest.raises(ValueError) as exc_info:+ impl.get_table_metadata(cursor, "dbo", "dropped_table")++ non_retryable = MSSQLSource().get_non_retryable_errors()+ assert any(pattern in str(exc_info.value) for pattern in non_retryable.keys())+class TestIsTransientConnectionError:@pytest.mark.parametrize(