diff --git a/exasol/driver/websocket/_connection.py b/exasol/driver/websocket/_connection.py index 07ee29b0..dd239a45 100644 --- a/exasol/driver/websocket/_connection.py +++ b/exasol/driver/websocket/_connection.py @@ -150,4 +150,16 @@ def cursor(self): return DefaultCursor(self) def __del__(self): - self.close() + if self._connection is None: + return + + # Currently, the only way to handle this gracefully is to invoke the`__del__` + # method of the underlying connection rather than calling an explicit `close`. + # + # For more details, see also: + # * https://github.com/exasol/sqlalchemy-exasol/issues/390 + # * https://github.com/exasol/pyexasol/issues/108 + # + # If the above tickets are resolved, it should be safe to switch back to using + # `close` instead of `__del__`. + self._connection.__del__() diff --git a/test/integration/regression/test_regression_bug390.py b/test/integration/regression/test_regression_bug390.py index e3013270..b634001b 100644 --- a/test/integration/regression/test_regression_bug390.py +++ b/test/integration/regression/test_regression_bug390.py @@ -3,14 +3,14 @@ pytest_plugins = "pytester" -def test_connection_with_block_cleans_up_properly(pytester, itde): - config = itde.db +def test_connection_with_block_cleans_up_properly(pytester, exasol_config): + config = exasol_config # Because the error only occurs on process shutdown we need to run a test within a test # (We require the result (stderr) of a terminated process triggering the failure. pytester.makepyfile( # fmt: off cleandoc( - f""" + f""" from sqlalchemy import create_engine def test(): @@ -20,7 +20,7 @@ def test(): pw="{config.password}", host="{config.host}", port={config.port}, - schema="{itde.itde.schemas[0]}", + schema="TEST", ) engine = create_engine(url) query = "SELECT 42;"