Skip to content

Commit 76fb63f

Browse files
Remove duplicate methods from async dialect
DqliteDialect_aio needlessly overrode create_connect_args, do_rollback, do_commit, and _get_server_version_info with identical copies from the base DqliteDialect. Remove them so the async dialect inherits instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a4d0328 commit 76fb63f

2 files changed

Lines changed: 15 additions & 45 deletions

File tree

src/sqlalchemydqlite/aio.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from sqlalchemy import pool
88
from sqlalchemy.engine import URL, AdaptedConnection
9-
from sqlalchemy.engine.interfaces import DBAPIConnection
109
from sqlalchemy.pool import AsyncAdaptedQueuePool
1110
from sqlalchemy.util import await_only
1211

@@ -146,50 +145,6 @@ def connect(self, *cargs: Any, **cparams: Any) -> Any:
146145
raw_conn = self.loaded_dbapi.connect(*cargs, **cparams)
147146
return AsyncAdaptedConnection(raw_conn)
148147

149-
def create_connect_args(self, url: URL) -> tuple[list[Any], dict[str, Any]]:
150-
"""Create connection arguments from URL.
151-
152-
URL format: dqlite+aio://host:port/database
153-
"""
154-
host = url.host or "localhost"
155-
port = url.port or 9001
156-
database = url.database or "default"
157-
158-
address = f"{host}:{port}"
159-
160-
return [], {
161-
"address": address,
162-
"database": database,
163-
}
164-
165-
def do_rollback(self, dbapi_connection: DBAPIConnection) -> None:
166-
"""Rollback the current transaction."""
167-
try:
168-
dbapi_connection.rollback()
169-
except Exception as e:
170-
if "no transaction is active" not in str(e):
171-
raise
172-
173-
def do_commit(self, dbapi_connection: DBAPIConnection) -> None:
174-
"""Commit the current transaction."""
175-
try:
176-
dbapi_connection.commit()
177-
except Exception as e:
178-
if "no transaction is active" not in str(e):
179-
raise
180-
181-
def _get_server_version_info(self, connection: Any) -> tuple[int, ...]:
182-
"""Return the server version as a tuple."""
183-
cursor = connection.connection.dbapi_connection.cursor()
184-
cursor.execute("SELECT sqlite_version()")
185-
row = cursor.fetchone()
186-
cursor.close()
187-
188-
if row:
189-
version_str = row[0]
190-
return tuple(int(x) for x in version_str.split("."))
191-
return (3, 0, 0)
192-
193148
def get_driver_connection(self, connection: Any) -> Any:
194149
"""Return the driver-level connection."""
195150
return connection

tests/test_dialect.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ def test_dialect_is_async(self) -> None:
5454
dialect = DqliteDialect_aio()
5555
assert dialect.is_async is True
5656

57+
def test_inherits_shared_methods_from_base(self) -> None:
58+
"""Async dialect should inherit shared methods from base, not duplicate them."""
59+
shared_methods = [
60+
"create_connect_args",
61+
"do_rollback",
62+
"do_commit",
63+
"_get_server_version_info",
64+
]
65+
for method_name in shared_methods:
66+
base_method = getattr(DqliteDialect, method_name)
67+
aio_method = getattr(DqliteDialect_aio, method_name)
68+
assert base_method is aio_method, (
69+
f"{method_name} is overridden in DqliteDialect_aio but should be inherited"
70+
)
71+
5772
def test_import_dbapi(self) -> None:
5873
dbapi = DqliteDialect_aio.import_dbapi()
5974
assert hasattr(dbapi, "aconnect")

0 commit comments

Comments
 (0)