From f9552642fe212d114a3670068dc73243594a0cec Mon Sep 17 00:00:00 2001 From: Elliana May Date: Thu, 25 Aug 2022 20:54:31 +0800 Subject: [PATCH] fix: fix bleeding edge duckdb for exceptions changes --- duckdb_engine/__init__.py | 4 +++- duckdb_engine/tests/test_basic.py | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/duckdb_engine/__init__.py b/duckdb_engine/__init__.py index 17a8ad8a..6a66b152 100644 --- a/duckdb_engine/__init__.py +++ b/duckdb_engine/__init__.py @@ -33,6 +33,8 @@ class DBAPI: # this is being fixed upstream to add a proper exception hierarchy Error = getattr(duckdb, "Error", RuntimeError) + TransactionException = getattr(duckdb, "TransactionException", Error) + ParserException = getattr(duckdb, "ParserException", Error) @staticmethod def Binary(x: Any) -> Any: @@ -188,7 +190,7 @@ def get_default_isolation_level(self, connection: "Connection") -> None: def do_rollback(self, connection: "Connection") -> None: try: super().do_rollback(connection) - except RuntimeError as e: + except DBAPI.TransactionException as e: if ( e.args[0] != "TransactionContext Error: cannot rollback - no transaction is active" diff --git a/duckdb_engine/tests/test_basic.py b/duckdb_engine/tests/test_basic.py index 6a405d99..2d4b4a0f 100644 --- a/duckdb_engine/tests/test_basic.py +++ b/duckdb_engine/tests/test_basic.py @@ -261,9 +261,7 @@ def test_binary(session: Session) -> None: def test_comment_support() -> None: "comments not yet supported by duckdb" - exc = getattr(duckdb, "StandardException", DBAPI.Error) - - with raises(exc, match="syntax error"): + with raises(DBAPI.ParserException, match="syntax error"): duckdb.default_connection.execute('comment on sqlite_master is "hello world";')