Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
ai: apply changes for #877 (1 review thread)
Addresses:
  - #3635886434 at tests/e2e/test_driver.py:1159

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
  • Loading branch information
peco-engineer-bot[bot] committed Jul 23, 2026
commit bc07abfecae3e6e8fc9937b2e42bcc63ab0d5750
32 changes: 32 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@ class ClientTestSuite(unittest.TestCase):
"enable_telemetry": False,
}

@patch("%s.client.Session" % PACKAGE_NAME)
def test_del_does_not_raise_when_session_never_set(self, mock_session_class):
"""A constructor-stage failure must not leave __del__ raising on GC.

When the Session constructor raises before ``self.session`` is assigned
in Connection.__init__, the original error must propagate, and __del__ on
the half-constructed Connection must not raise (which Python reports as an
'Exception ignored in __del__' referencing the missing ``session``
attribute). See https://github.com/databricks/databricks-sql-python/issues/746
"""
mock_session_class.side_effect = ValueError("bad auth")

unraisable = []
original_hook = sys.unraisablehook
sys.unraisablehook = lambda args: unraisable.append(args)
try:
with self.assertRaises(ValueError):
client.Connection(**self.DUMMY_CONNECTION_ARGS)

# Force collection of the half-constructed Connection so __del__ runs.
gc.collect()
finally:
sys.unraisablehook = original_hook

messages = [
"{}: {}".format(type(u.exc_value).__name__, u.exc_value)
for u in unraisable
]
self.assertEqual(
unraisable, [], "Exception(s) raised in __del__: {}".format(messages)
)

@patch("%s.session.ThriftDatabricksClient" % PACKAGE_NAME)
def test_closing_connection_closes_commands(self, mock_thrift_client_class):
"""Test that closing a connection properly closes commands.
Expand Down
Loading