This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 1f3bf1170 feat(python/adbc_driver_manager): simplify autocommit=True 
(#2990)
1f3bf1170 is described below

commit 1f3bf1170f844d41cd8df2679dc8748c670c317c
Author: David Li <[email protected]>
AuthorDate: Thu Jun 19 10:03:20 2025 +0900

    feat(python/adbc_driver_manager): simplify autocommit=True (#2990)
    
    Fixes #2987
---
 .../adbc_driver_manager/dbapi.py                   | 26 +++++++++++-----------
 python/adbc_driver_sqlite/tests/test_dbapi.py      |  1 +
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/python/adbc_driver_manager/adbc_driver_manager/dbapi.py 
b/python/adbc_driver_manager/adbc_driver_manager/dbapi.py
index d0a76db74..03860e1e4 100644
--- a/python/adbc_driver_manager/adbc_driver_manager/dbapi.py
+++ b/python/adbc_driver_manager/adbc_driver_manager/dbapi.py
@@ -312,23 +312,23 @@ class Connection(_Closeable):
         self._conn = conn
         self._conn_kwargs = conn_kwargs
 
-        try:
-            self._conn.set_autocommit(False)
-        except _lib.NotSupportedError:
+        if autocommit:
+            self._autocommit = True
             self._commit_supported = False
-            if not autocommit:
+        else:
+            try:
+                self._conn.set_autocommit(False)
+            except _lib.NotSupportedError:
+                self._commit_supported = False
                 warnings.warn(
-                    "Cannot disable autocommit; conn will not be DB-API 2.0 
compliant",
+                    "Cannot disable autocommit; "
+                    "conn will not be DB-API 2.0 compliant",
                     category=Warning,
                 )
-            self._autocommit = True
-        else:
-            self._autocommit = False
-            self._commit_supported = True
-
-        if autocommit and self._commit_supported:
-            self._conn.set_autocommit(True)
-            self._autocommit = True
+                self._autocommit = True
+            else:
+                self._autocommit = False
+                self._commit_supported = True
 
     def close(self) -> None:
         """
diff --git a/python/adbc_driver_sqlite/tests/test_dbapi.py 
b/python/adbc_driver_sqlite/tests/test_dbapi.py
index 47fdcc9d1..ae672e4bb 100644
--- a/python/adbc_driver_sqlite/tests/test_dbapi.py
+++ b/python/adbc_driver_sqlite/tests/test_dbapi.py
@@ -50,6 +50,7 @@ def test_autocommit(tmp_path: Path) -> None:
     # This now works if we enable autocommit
     with dbapi.connect(f"file:{db}", autocommit=True) as conn:
         assert conn._autocommit
+        assert not conn._commit_supported
         with conn.cursor() as cur:
             cur.execute("PRAGMA journal_mode = WAL")
 

Reply via email to