From a4530d1b6a6388adc50418d1f389b0cb8c0db2ea Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:10:11 -0400 Subject: [PATCH] chore: avoid explicit commit if we are in autocommit mode --- ibis/backends/mysql/__init__.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ibis/backends/mysql/__init__.py b/ibis/backends/mysql/__init__.py index a22447b76b02c..fb9ce68453aa4 100644 --- a/ibis/backends/mysql/__init__.py +++ b/ibis/backends/mysql/__init__.py @@ -255,13 +255,19 @@ def drop_database(self, name: str, force: bool = False) -> None: def begin(self): con = self.con cur = con.cursor() + + if not con.autocommit_mode: + con.begin() + try: yield cur except Exception: - con.rollback() + if not con.autocommit_mode: + con.rollback() raise else: - con.commit() + if not con.autocommit_mode: + con.commit() finally: cur.close() @@ -279,14 +285,19 @@ def raw_sql(self, query: str | sg.Expression, **kwargs: Any) -> Any: con = self.con cursor = con.cursor() + if not con.autocommit_mode: + con.begin() + try: cursor.execute(query, **kwargs) except Exception: - con.rollback() + if not con.autocommit_mode: + con.rollback() cursor.close() raise else: - con.commit() + if not con.autocommit_mode: + con.commit() return cursor # TODO: disable positional arguments