Skip to content

Commit

Permalink
Fix closing cursor with no previously running query
Browse files Browse the repository at this point in the history
  • Loading branch information
hovaesco authored and hashhar committed Dec 22, 2023
1 parent f99ef24 commit 86ed4da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 4 additions & 6 deletions tests/integration/test_dbapi_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,10 +1343,9 @@ def test_cancel_query(trino_connection):
cur.fetchone()
cur.cancel() # would raise an exception if cancel fails

# verify that it doesn't fail in the absence of a previously running query
cur = trino_connection.cursor()
with pytest.raises(Exception) as cancel_error:
cur.cancel()
assert "Cancel query failed; no running query" in str(cancel_error.value)
cur.cancel()


def test_close_cursor(trino_connection):
Expand All @@ -1355,10 +1354,9 @@ def test_close_cursor(trino_connection):
cur.fetchone()
cur.close() # would raise an exception if cancel fails

# verify that it doesn't fail in the absence of a previously running query
cur = trino_connection.cursor()
with pytest.raises(Exception) as cancel_error:
cur.close()
assert "Cancel query failed; no running query" in str(cancel_error.value)
cur.close()


def test_session_properties(run_trino):
Expand Down
4 changes: 1 addition & 3 deletions trino/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,7 @@ def fetchall(self) -> List[List[Any]]:

def cancel(self):
if self._query is None:
raise trino.exceptions.OperationalError(
"Cancel query failed; no running query"
)
return
self._query.cancel()

def close(self):
Expand Down

0 comments on commit 86ed4da

Please sign in to comment.