diff --git a/superset/db_engine_specs/mssql.py b/superset/db_engine_specs/mssql.py index 5d29d36ba89b7..d5cc86c859a7b 100644 --- a/superset/db_engine_specs/mssql.py +++ b/superset/db_engine_specs/mssql.py @@ -141,6 +141,8 @@ def convert_dttm( def fetch_data( cls, cursor: Any, limit: Optional[int] = None ) -> list[tuple[Any, ...]]: + if not cursor.description: + return [] data = super().fetch_data(cursor, limit) # Lists of `pyodbc.Row` need to be unpacked further return cls.pyodbc_rows_to_tuples(data) diff --git a/tests/unit_tests/db_engine_specs/test_mssql.py b/tests/unit_tests/db_engine_specs/test_mssql.py index 8149e60cd83ee..56ff8879229e5 100644 --- a/tests/unit_tests/db_engine_specs/test_mssql.py +++ b/tests/unit_tests/db_engine_specs/test_mssql.py @@ -157,6 +157,14 @@ def test_extract_error_message() -> None: assert expected_message == error_message +def test_fetch_data_no_description() -> None: + from superset.db_engine_specs.mssql import MssqlEngineSpec + + cursor = mock.MagicMock() + cursor.description = [] + assert MssqlEngineSpec.fetch_data(cursor) == [] + + def test_fetch_data() -> None: from superset.db_engine_specs.base import BaseEngineSpec from superset.db_engine_specs.mssql import MssqlEngineSpec @@ -166,9 +174,10 @@ def test_fetch_data() -> None: "pyodbc_rows_to_tuples", return_value="converted", ) as mock_pyodbc_rows_to_tuples: + cursor = mock.MagicMock() data = [(1, "foo")] with mock.patch.object(BaseEngineSpec, "fetch_data", return_value=data): - result = MssqlEngineSpec.fetch_data(None, 0) + result = MssqlEngineSpec.fetch_data(cursor, 0) mock_pyodbc_rows_to_tuples.assert_called_once_with(data) assert result == "converted"