Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mssql): avoid trying to return a resultset for DML queries with not resultset #24999

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading