Skip to content

Commit

Permalink
Fix test for closeSession
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Whitehouse <[email protected]>
  • Loading branch information
Jesse Whitehouse committed Aug 3, 2023
1 parent d27466a commit 64b45ef
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/databricks/sql/auth/thrift_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from io import BytesIO

from urllib3 import HTTPConnectionPool, HTTPSConnectionPool, ProxyManager, Retry
from databricks.sql.exc import MaxRetryDurationError, NonRecoverableNetworkError, UnsafeToRetryError
from databricks.sql.exc import MaxRetryDurationError, NonRecoverableNetworkError, UnsafeToRetryError, SessionAlreadyClosedError
from enum import Enum, auto


Expand Down Expand Up @@ -188,9 +188,9 @@ def should_retry(self, method: str, status_code: int) -> bool:
if (
status_code == 404 and
self.command_type in [CommandType.CANCEL_OPERATION, CommandType.CLOSE_SESSION]
and len(self.history) > 1
and len(self.history) > 0
):
return False
raise SessionAlreadyClosedError("CloseSession received 404 code from Databricks. Session is already closed.")


# Request failed, was an ExecuteStatement and the command may have reached the server
Expand Down
5 changes: 3 additions & 2 deletions src/databricks/sql/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ def _close(self, close_cursors=True) -> None:

try:
self.thrift_backend.close_session(self._session_handle)
except SessionAlreadyClosedError as e:
logger.info("Session was closed by a prior request")
except RequestError as e:
if isinstance(e.args[1], SessionAlreadyClosedError):
logger.info("Session was closed by a prior request")
except DatabaseError as e:
if "Invalid SessionHandle" in str(e):
logger.warning(
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/common/retry_test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ def test_retry_abort_close_session_on_404(self):
]

with self.connection(extra_params={**self._retry_policy}) as conn:
conn.close()
conn.open = True
with mock_sequential_server_responses(responses):
with self.assertLogs("databricks.sql", level="INFO",) as cm:
conn.close()
Expand Down

0 comments on commit 64b45ef

Please sign in to comment.