Skip to content

Commit

Permalink
Merge pull request #390 from Mause/bugfix/fix-bleeding-edge-for-excep…
Browse files Browse the repository at this point in the history
…tions

fix: fix bleeding edge duckdb for exceptions changes
  • Loading branch information
Mause authored Aug 25, 2022
2 parents df29c6a + f955264 commit 7dae043
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 3 additions & 1 deletion duckdb_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions duckdb_engine/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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";')


Expand Down

0 comments on commit 7dae043

Please sign in to comment.