Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitafcb0f0

Browse files
author
Jesse
authored
[ES-402013] Close cursors before closing connection (#38)
* Add test: cursors are closed when connection closesSigned-off-by: Jesse Whitehouse <jesse@whitehouse.dev>
1 parent6bafb9d commitafcb0f0

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

‎src/databricks/sql/client.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,11 @@ def close(self) -> None:
181181
self._close()
182182

183183
def_close(self,close_cursors=True)->None:
184-
self.thrift_backend.close_session(self._session_handle)
185-
self.open=False
186-
187184
ifclose_cursors:
188185
forcursorinself._cursors:
189186
cursor.close()
187+
self.thrift_backend.close_session(self._session_handle)
188+
self.open=False
190189

191190
defcommit(self):
192191
"""No-op because Databricks does not support transactions"""

‎tests/e2e/driver_tests.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,32 @@ def test_decimal_not_returned_as_strings_arrow(self):
544544
decimal_type=arrow_df.field(0).type
545545
self.assertTrue(pyarrow.types.is_decimal(decimal_type))
546546

547+
deftest_close_connection_closes_cursors(self):
548+
549+
fromdatabricks.sql.thrift_api.TCLIServiceimportttypes
550+
551+
withself.connection()asconn:
552+
cursor=conn.cursor()
553+
cursor.execute('SELECT id, id `id2`, id `id3` FROM RANGE(1000000) order by RANDOM()')
554+
ars=cursor.active_result_set
555+
556+
# We must manually run this check because thrift_backend always forces `has_been_closed_server_side` to True
557+
558+
# Cursor op state should be open before connection is closed
559+
status_request=ttypes.TGetOperationStatusReq(operationHandle=ars.command_id,getProgressUpdate=False)
560+
op_status_at_server=ars.thrift_backend._client.GetOperationStatus(status_request)
561+
assertop_status_at_server.operationState!=ttypes.TOperationState.CLOSED_STATE
562+
563+
conn.close()
564+
565+
# When connection closes, any cursor operations should no longer exist at the server
566+
withself.assertRaises(thrift.Thrift.TApplicationException)ascm:
567+
op_status_at_server=ars.thrift_backend._client.GetOperationStatus(status_request)
568+
ifhasattr(cm,"exception"):
569+
assert"RESOURCE_DOES_NOT_EXIST"incm.exception.message
570+
571+
572+
547573

548574
# use a RetrySuite to encapsulate these tests which we'll typically want to run together; however keep
549575
# the 429/503 subsuites separate since they execute under different circumstances.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp