mirror of
https://github.com/apache/superset.git
synced 2026-04-18 15:44:57 +00:00
fix(mssql): avoid trying to return a resultset for DML queries with not resultset (#24999)
This commit is contained in:
@@ -141,6 +141,8 @@ class MssqlEngineSpec(BaseEngineSpec):
|
||||
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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user