Skip to content

Commit 6394dbb

Browse files
committed
Fix return type of async DictCursor queries
1 parent 80253de commit 6394dbb

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
@@ -414,7 +414,7 @@ def __init__(
414414
self._first_chunk_time = None
415415

416416
self._log_max_query_length = connection.log_max_query_length
417-
self._inner_cursor: SnowflakeCursor | None = None
417+
self._inner_cursor: SnowflakeCursorBase | None = None
418418
self._prefetch_hook = None
419419
self._rownumber: int | None = None
420420

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

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

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

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)