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(mssql): treat invalid object/column name errors as non-retryable (#64024)

Tom Owers9ee62b206be4
diff --git a/posthog/temporal/data_imports/sources/mssql/source.py b/posthog/temporal/data_imports/sources/mssql/source.py
index 24fc31a273cb..2b4012b92472 100644
--- a/posthog/temporal/data_imports/sources/mssql/source.py
+++ b/posthog/temporal/data_imports/sources/mssql/source.py
@@ -65,6 +65,11 @@ class MSSQLSource(SQLSource[MSSQLSourceConfig], SSHTunnelMixin, ValidateDatabase
# not the volatile object name / procedure / line number in the rest of the message.
"Invalid object name": "One of the tables or views you're syncing references a database object that no longer exists or that this login can't access (SQL Server error 208). Check that the object still exists and that the connection user has permission to read it (including any tables a view depends on), then re-sync.",
"Cannot find the CREDENTIAL": "Cannot find the credential - check that it exists and you have permission to access it",
+ # SQL Server error 207, the column-level counterpart of 208: the `SELECT` references a
+ # column that doesn't exist — a column dropped or renamed at the source, or a view
+ # whose definition selects a column that's no longer present. Fixed source-data shape,
+ # so retrying won't help.
+ "Invalid column name": "One of the columns being synced no longer exists in your SQL Server. A column was likely dropped or renamed, or a view's definition references a column that's no longer present. Fix the column or view definition at the source, then re-enable the sync.",
# Raised by the `sshtunnel` library (via the shared `open_ssh_tunnel` helper) when the
# SSH tunnel can't be brought up — the bastion host is unreachable, the host/port is
# wrong, the SSH key/credentials are rejected, or a firewall blocks PostHog's IPs. This
diff --git a/posthog/temporal/data_imports/sources/mssql/tests/test_mssql.py b/posthog/temporal/data_imports/sources/mssql/tests/test_mssql.py
index bae3917f6329..07bdc91422e0 100644
--- a/posthog/temporal/data_imports/sources/mssql/tests/test_mssql.py
+++ b/posthog/temporal/data_imports/sources/mssql/tests/test_mssql.py
@@ -514,3 +514,19 @@ class TestMSSQLSourceNonRetryableErrors:
def test_invalid_object_name_is_non_retryable(self, error_msg):
non_retryable = MSSQLSource().get_non_retryable_errors()
assert any(pattern in error_msg for pattern in non_retryable.keys()), error_msg
+
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # SQL Server error 207 — a referenced column no longer exists (dropped/renamed at the
+ # source, or a view body that selects a column that's gone). Real pymssql message.
+ "SQL Server message 207, severity 16, state 1, procedure b'\\xb0z\\x16,\\xff\\xff', line 39:\n"
+ "Invalid column name 'usr_modelo'.DB-Lib error message 20018, severity 16:\n"
+ "General SQL Server error: Check messages from the SQL Server",
+ # Different column name must still match the stable substring.
+ "Invalid column name 'created_at'.",
+ ],
+ )
+ def test_invalid_column_name_is_non_retryable(self, error_msg):
+ non_retryable = MSSQLSource().get_non_retryable_errors()
+ assert any(pattern in error_msg for pattern in non_retryable.keys()), error_msg