fix: handle `set_isolation_level` gracefully
Whenever the sqlachemy tries to use set_isolation_level without it being defined it will cast object has no attribute 'set_isolation_level' instead of gracefully handling the error by explicitly raising NotImplementedError
hey there, thanks for submitting this PR! any chance we could see a test demonstrating the issue and proving that it's fixed?
You can check this by using:
from sqlalchemy import create_engine
eng = create_engine("duckdb:///:memory:", execution_options={"isolation_level": "AUTOCOMMIT"})
try:
conn = eng.connect()
except NotImplementedError:
print('Expected not implemented error raised!')
except Exception as e:
raise(e)
This will allow other libraries using duckdb-engine to more gracefully handle expected errors, since engine PGDialect implements set_isolation_level, but duckdb does not.
I rebased against main for merging!
Or if you want to wrap it within unittest for automated tests:
from sqlalchemy import create_engine
import unittest
class TestDuckDBDialect(unittest.TestCase):
def test_set_isolation_level_not_supported(self):
eng = create_engine("duckdb:///:memory:", execution_options={"isolation_level": "AUTOCOMMIT"})
with self.assertRaises(NotImplementedError):
eng.connect()
eng.dispose()
if __name__ == '__main__':
unittest.main()