Skip to content

Commit

Permalink
Fix cancel: request right endpoint to cancel a query
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Leclercq committed Jul 18, 2019
1 parent a8aa7d5 commit 10e8ffd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 1 addition & 5 deletions integration_tests/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ def test_select_tpch_1000(presto_connection):
def test_cancel_query(presto_connection):
cur = presto_connection.cursor()
cur.execute("select * from tpch.sf1.customer")
cur.cancel()

with pytest.raises(prestodb.exceptions.PrestoUserError) as cancel_error:
cur.fetchall()
assert "Query was canceled" in str(cancel_error.value)
cur.cancel() # would raise an exception if cancel fails

cur = presto_connection.cursor()
with pytest.raises(Exception) as cancel_error:
Expand Down
11 changes: 6 additions & 5 deletions prestodb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,16 @@ def fetch(self):
def cancel(self):
# type: () -> None
"""Cancel the current query"""
if self.is_finished():
if self.query_id is None or self.is_finished():
return

self._cancelled = True
if self._request.next_uri is None:
return

response = self._request.delete(self._request.next_uri)
url = self._request.get_url("/v1/query/{}".format(self.query_id))
logger.debug("cancelling query: %s", self.query_id)
response = self._request.delete(url)
logger.info(response)
if response.status_code == requests.codes.no_content:
logger.debug("query cancelled: %s", self.query_id)
return
self._request.raise_response_error(response)

Expand Down

0 comments on commit 10e8ffd

Please sign in to comment.