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 committed Dec 21, 2023
1 parent f99ef24 commit 3cb197d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
10 changes: 0 additions & 10 deletions tests/integration/test_dbapi_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,23 +1343,13 @@ def test_cancel_query(trino_connection):
cur.fetchone()
cur.cancel() # would raise an exception if cancel fails

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)


def test_close_cursor(trino_connection):
cur = trino_connection.cursor()
cur.execute("SELECT * FROM tpch.sf1.customer")
cur.fetchone()
cur.close() # would raise an exception if cancel fails

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)


def test_session_properties(run_trino):
_, host, port = 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 3cb197d

Please sign in to comment.