You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/08/21 11:33:33 UTC
[superset] branch master updated: fix(mssql): avoid trying to return a resultset for DML queries with not resultset (#24999)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 66eabc253f fix(mssql): avoid trying to return a resultset for DML queries with not resultset (#24999)
66eabc253f is described below
commit 66eabc253faf2c27db5aaf5283ab2e00fedaa817
Author: Yuval Moshe <53...@users.noreply.github.com>
AuthorDate: Mon Aug 21 14:33:26 2023 +0300
fix(mssql): avoid trying to return a resultset for DML queries with not resultset (#24999)
---
superset/db_engine_specs/mssql.py | 2 ++
tests/unit_tests/db_engine_specs/test_mssql.py | 11 ++++++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/superset/db_engine_specs/mssql.py b/superset/db_engine_specs/mssql.py
index 5d29d36ba8..d5cc86c859 100644
--- a/superset/db_engine_specs/mssql.py
+++ b/superset/db_engine_specs/mssql.py
@@ -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)
diff --git a/tests/unit_tests/db_engine_specs/test_mssql.py b/tests/unit_tests/db_engine_specs/test_mssql.py
index 8149e60cd8..56ff887922 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"