diff --git a/CHANGES.txt b/CHANGES.txt index 216527a..76d3b78 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,9 @@ Changes ------- +0.5.1 (unreleased) +^^^^^^^^^^^^^^^^^ +* Ensure close() runs even if rollback() fails (fix #471) + 0.5.0 (2023-10-28) ^^^^^^^^^^^^^^^^^^ * Added support for python 3.12 diff --git a/aioodbc/connection.py b/aioodbc/connection.py index 8e7ccab..f275ba5 100644 --- a/aioodbc/connection.py +++ b/aioodbc/connection.py @@ -19,8 +19,10 @@ async def _close_cursor(c: Cursor) -> None: async def _close_cursor_on_error(c: Cursor) -> None: - await c.rollback() - await c.close() + try: + await c.rollback() + finally: + await c.close() class Connection: @@ -248,8 +250,10 @@ async def _disconnect(c: "Connection") -> None: async def _disconnect_on_error(c: "Connection") -> None: - await c.rollback() - await c.close() + try: + await c.rollback() + finally: + await c.close() async def _connect(