Skip to content

Commit 0bf1c0b

Browse files
committed
Add test that cursors are closed when connection closes.
Test fails in this commit. Only explicitly indicate that the cursors was closed server side if we are certain this happened. That is, this attr must be True _before_ this method was called or as a result of its oper- ation. Previous behaviour would set the attr=True even if the connection was already closed, which is not correct. Signed-off-by: Jesse Whitehouse <[email protected]>
1 parent a49072e commit 0bf1c0b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/databricks/sql/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,8 @@ def close(self) -> None:
719719
and self.connection.open
720720
):
721721
self.thrift_backend.close_command(self.command_id)
722+
self.has_been_closed_server_side = True
722723
finally:
723-
self.has_been_closed_server_side = True
724724
self.op_state = self.thrift_backend.CLOSED_OP_STATE
725725

726726
@staticmethod

tests/e2e/driver_tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,17 @@ 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+
def test_close_connection_closes_cursors(self):
548+
with self.connection() as conn:
549+
cursor = conn.cursor()
550+
cursor.execute('SELECT id, id `id2`, id `id3` FROM RANGE(1000000) order by RANDOM()')
551+
ars = cursor.active_result_set
552+
assert not bool(ars.has_been_closed_server_side)
553+
conn.close()
554+
assert bool(ars.has_been_closed_server_side)
555+
cursor.close()
556+
557+
547558

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

0 commit comments

Comments
 (0)