Skip to content

Commit 704dae3

Browse files
mathiasritterMathias Ritter
authored andcommitted
SQLAlchemy 2.0 Compatibility
In the do_execute function of SQLAlchemy dialect, an if statement was accessing context.should_autocommit. This property has been removed in SQLAlchemy 2.0. To fix, the if statement can simply be removed as it is no longer needed.
1 parent 8affa61 commit 704dae3

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ jobs:
5858
- { python: "3.11", trino: "351", sqlalchemy: "~=1.4.0" } # first Trino version
5959
# Test with sqlalchemy 1.3
6060
- { python: "3.11", trino: "latest", sqlalchemy: "~=1.3.0" }
61+
# Test with sqlalchemy 2.0
62+
- { python: "3.11", trino: "latest", sqlalchemy: "~=2.0.0b4" }
6163
env:
6264
TRINO_VERSION: "${{ matrix.trino }}"
6365
steps:

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
version = str(ast.literal_eval(trino_version.group(1)))
2727

2828
kerberos_require = ["requests_kerberos"]
29-
sqlalchemy_require = ["sqlalchemy~=1.3"]
29+
sqlalchemy_require = ["sqlalchemy >= 1.3"]
3030
external_authentication_token_cache_require = ["keyring"]
3131

3232
# We don't add localstorage_require to all_require as users must explicitly opt in to use keyring.
@@ -39,7 +39,7 @@
3939
"pytest",
4040
"pytest-runner",
4141
"click",
42-
"sqlalchemy_utils",
42+
"sqlalchemy_utils >= 0.39.0",
4343
"pre-commit",
4444
"black",
4545
"isort",
@@ -79,7 +79,7 @@
7979
"Programming Language :: Python :: Implementation :: PyPy",
8080
"Topic :: Database :: Front-Ends",
8181
],
82-
python_requires='>=3.7',
82+
python_requires=">=3.7",
8383
install_requires=["pytz", "requests", "tzlocal"],
8484
extras_require={
8585
"all": all_require,

trino/sqlalchemy/dialect.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,6 @@ def do_execute(
363363
self, cursor: Cursor, statement: str, parameters: Tuple[Any, ...], context: DefaultExecutionContext = None
364364
):
365365
cursor.execute(statement, parameters)
366-
if context and context.should_autocommit:
367-
# SQL statement only submitted to Trino server when cursor.fetch*() is called.
368-
# For DDL (CREATE/ALTER/DROP) and DML (INSERT/UPDATE/DELETE) statement, call cursor.description
369-
# to force submit statement immediately.
370-
cursor.description # noqa
371366

372367
def do_rollback(self, dbapi_connection: trino_dbapi.Connection):
373368
if dbapi_connection.transaction is not None:

0 commit comments

Comments
 (0)