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): stop tracking column-permission denials as bugs (#108841)

Tom Owers01e1bb7e4be9
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.py
index 0bd9820c67ef..9a58422b6ae8 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
@@ -837,8 +837,12 @@ class MSSQLImplementation(SQLSourceImplementation[MSSQLSourceConfig, pymssql.Con
row_size_bytes = max(row[0] or 0, 1)
return int(row_size_bytes)
except Exception as e:
+ # This `SELECT TOP 100 *` is a best-effort sample over the same table/columns as the
+ # real streaming query, same as `get_rows_to_sync` above: a genuine problem (missing
+ # column, permissions) resurfaces there and is classified through the normal
+ # retryable/non-retryable path. Capturing it here too would only flood error tracking
+ # with a handled duplicate.
logger.debug(f"fetch_average_row_size: Error: {e}.", exc_info=e)
- capture_exception(e)
return None
def get_rows_to_sync(
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.py
index a24d5e1a9bcf..60b1e00aeab8 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
@@ -101,6 +101,12 @@ class MSSQLSource(SQLSource[MSSQLSourceConfig], SSHTunnelMixin, ValidateDatabase
# same login can never succeed. Match the stable message text, not the object/database
# names that follow it.
"The SELECT permission was denied on the object": "Your SQL Server login doesn't have permission to read one of the tables or views being synced. Grant it SELECT access (for example via the db_datareader role or an explicit GRANT SELECT) on the objects you want to import, then re-enable the sync.",
+ # SQL Server error 230 — the column-level counterpart of 229: the login has some
+ # access to the object but a column-level GRANT/DENY blocks SELECT on one specific
+ # column ("...denied on the column 'X' of the object 'Y'..."). Same fix as the
+ # object-level case, just scoped to a column, so retrying replays the identical
+ # denial. Match the stable phrase, not the volatile column/object/database names.
+ "The SELECT permission was denied on the column": "Your SQL Server login doesn't have permission to read one of the columns being synced. Grant it SELECT access on that column (for example via the db_datareader role or an explicit column-level GRANT SELECT), then re-enable the sync.",
# SQL Server error 208 — the SELECT we run during the sync references an object the
# server can't resolve. Either the table/view we're syncing was dropped or renamed
# after schema discovery, or (as seen in practice) the view we select from has a body
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.py
index e97defcfc27d..2ba4b18fea0a 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
@@ -499,10 +499,19 @@ class TestFetchAverageRowSize:
result = impl.fetch_average_row_size(cursor, "dbo", "t", "SELECT 1", {}, logger)
assert result is None
- def test_returns_none_on_exception(self, impl, cursor, logger):
+ def test_returns_none_on_exception_without_capturing(self, impl, cursor, logger, mocker):
+ # This `SELECT TOP 100 *` shares its table/columns with the real streaming query, so a
+ # genuine problem (e.g. a column-level permission denial) resurfaces there and is
+ # captured/classified through the normal retryable/non-retryable path. Capturing it here
+ # too would flood error tracking with a handled duplicate — same reasoning as
+ # `get_rows_to_sync` below.
+ capture = mocker.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.mssql.mssql.capture_exception"
+ )
cursor.execute.side_effect = RuntimeError("boom")
result = impl.fetch_average_row_size(cursor, "dbo", "t", "SELECT 1", {}, logger)
assert result is None
+ capture.assert_not_called()
class TestGetRowsToSync:
@@ -696,6 +705,24 @@ class TestMSSQLSourceNonRetryableErrors:
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 230 — the column-level counterpart of 229: some access to the
+ # object, but a column-level GRANT/DENY blocks SELECT on one specific column.
+ "SQL Server message 230, severity 14, state 1, procedure b'', line 1:\n"
+ "b\"The SELECT permission was denied on the column 'Salary', of the object "
+ "'Employees', database 'mydb', schema 'dbo'.DB-Lib error message 20018, severity 14:\n"
+ 'General SQL Server error: Check messages from the SQL Server\n"',
+ # Different column/object/database names must still match the stable substring.
+ "The SELECT permission was denied on the column 'Notes', of the object 'Tickets', "
+ "database 'otherdb', schema 'dbo'.",
+ ],
+ )
+ def test_column_permission_denied_errors_are_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",
[