Skip to content

Commit 34d9d94

Browse files
committed
Fix return type of async DictCursor queries
1 parent 09d228b commit 34d9d94

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/snowflake/connector/cursor.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def __init__(
416416
self._first_chunk_time = None
417417

418418
self._log_max_query_length = connection.log_max_query_length
419-
self._inner_cursor: SnowflakeCursor | None = None
419+
self._inner_cursor: SnowflakeCursorBase | None = None
420420
self._prefetch_hook = None
421421
self._rownumber: int | None = None
422422

@@ -1722,20 +1722,31 @@ def wait_until_ready() -> None:
17221722
# Unset this function, so that we don't block anymore
17231723
self._prefetch_hook = None
17241724

1725-
if (
1726-
self._inner_cursor._total_rowcount == 1
1727-
and self._inner_cursor.fetchall()
1728-
== [("Multiple statements executed successfully.",)]
1725+
if self._inner_cursor._total_rowcount == 1 and _is_successful_multi_stmt(
1726+
self._inner_cursor.fetchall()
17291727
):
17301728
url = f"/queries/{sfqid}/result"
17311729
ret = self._connection.rest.request(url=url, method="get")
17321730
if "data" in ret and "resultIds" in ret["data"]:
17331731
self._init_multi_statement_results(ret["data"])
17341732

1733+
def _is_successful_multi_stmt(rows: list[Any]) -> True:
1734+
if len(rows) != 1:
1735+
return False
1736+
row = rows[0]
1737+
if isinstance(row, tuple):
1738+
return row == ("Multiple statements executed successfully.",)
1739+
elif isinstance(row, dict):
1740+
return row == {
1741+
"multiple statement execution": "Multiple statements executed successfully."
1742+
}
1743+
else:
1744+
return False
1745+
17351746
self.connection.get_query_status_throw_if_error(
17361747
sfqid
17371748
) # Trigger an exception if query failed
1738-
self._inner_cursor = SnowflakeCursor(self.connection)
1749+
self._inner_cursor = self.__class__(self.connection)
17391750
self._sfqid = sfqid
17401751
self._prefetch_hook = wait_until_ready
17411752

test/integ/test_async.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
QueryStatus = None
1919

2020

21-
@pytest.mark.parametrize("cursor_class", [SnowflakeCursor, DictCursor])
22-
def test_simple_async(conn_cnx, cursor_class):
21+
@pytest.mark.parametrize(
22+
"cursor_class, row_type", [(SnowflakeCursor, tuple), (DictCursor, dict)]
23+
)
24+
def test_simple_async(conn_cnx, cursor_class, row_type):
2325
"""Simple test to that shows the most simple usage of fire and forget.
2426
2527
This test also makes sure that wait_until_ready function's sleeping is tested and
@@ -29,7 +31,9 @@ def test_simple_async(conn_cnx, cursor_class):
2931
with con.cursor(cursor_class) as cur:
3032
cur.execute_async("select count(*) from table(generator(timeLimit => 5))")
3133
cur.get_results_from_sfqid(cur.sfqid)
32-
assert len(cur.fetchall()) == 1
34+
rows = cur.fetchall()
35+
assert len(rows) == 1
36+
assert isinstance(rows[0], row_type)
3337
assert cur.rowcount
3438
assert cur.description
3539

0 commit comments

Comments
 (0)