Skip to content

Commit

Permalink
fix(mssql): avoid trying to return a resultset for DML queries with n…
Browse files Browse the repository at this point in the history
…ot resultset (#24999)
  • Loading branch information
Yuval-Moshe authored Aug 21, 2023
1 parent 3579861 commit 66eabc2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions superset/db_engine_specs/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion tests/unit_tests/db_engine_specs/test_mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down

0 comments on commit 66eabc2

Please sign in to comment.