Skip to content

Commit 063cc51

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 063cc51

File tree

3 files changed

+68
-70
lines changed

3 files changed

+68
-70
lines changed

.github/workflows/ci.yml

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,78 @@
11
name: ci
22

33
on:
4-
push:
5-
branches:
6-
- "master"
7-
pull_request:
8-
paths-ignore:
9-
- '**.md'
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
paths-ignore:
9+
- "**.md"
1010

1111
# Cancel previous PR builds.
1212
concurrency:
13-
# Cancel all workflow runs except latest within a concurrency group. This is achieved by defining a concurrency group for the PR.
14-
# Non-PR builds have singleton concurrency groups.
15-
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.number || github.sha }}
16-
cancel-in-progress: true
13+
# Cancel all workflow runs except latest within a concurrency group. This is achieved by defining a concurrency group for the PR.
14+
# Non-PR builds have singleton concurrency groups.
15+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.number || github.sha }}
16+
cancel-in-progress: true
1717

1818
jobs:
19-
checks:
20-
runs-on: ubuntu-latest
21-
steps:
22-
- name: "Checkout the source code"
23-
uses: actions/checkout@v3
19+
checks:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: "Checkout the source code"
23+
uses: actions/checkout@v3
2424

25-
- name: "Install Python"
26-
uses: actions/setup-python@v4
27-
with:
28-
python-version: "3.11"
25+
- name: "Install Python"
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: "3.11"
2929

30-
- name: "Install pre-commit"
31-
run: pip install pre-commit
30+
- name: "Install pre-commit"
31+
run: pip install pre-commit
3232

33-
- name: "Run pre-commit checks"
34-
run: pre-commit run --hook-stage manual --all-files
33+
- name: "Run pre-commit checks"
34+
run: pre-commit run --hook-stage manual --all-files
3535

36-
build:
37-
runs-on: ubuntu-latest
38-
strategy:
39-
fail-fast: false
40-
matrix:
41-
python: [
42-
"3.7",
43-
"3.8",
44-
"3.9",
45-
"3.10",
46-
"3.11",
47-
"pypy-3.8",
48-
"pypy-3.9",
49-
]
50-
trino: [
51-
"latest",
52-
]
53-
sqlalchemy: [
54-
"~=1.4.0"
55-
]
56-
include:
57-
# Test with older Trino versions for backward compatibility
58-
- { python: "3.11", trino: "351", sqlalchemy: "~=1.4.0" } # first Trino version
59-
# Test with sqlalchemy 1.3
60-
- { python: "3.11", trino: "latest", sqlalchemy: "~=1.3.0" }
61-
env:
62-
TRINO_VERSION: "${{ matrix.trino }}"
63-
steps:
64-
- uses: actions/checkout@v3
65-
- uses: actions/setup-python@v4
66-
with:
67-
python-version: ${{ matrix.python }}
68-
- name: Install dependencies
69-
run: |
70-
sudo apt-get update
71-
sudo apt-get install libkrb5-dev
72-
pip install .[tests] sqlalchemy${{ matrix.sqlalchemy }}
73-
- name: Run tests
74-
run: |
75-
pytest -s tests/
36+
build:
37+
runs-on: ubuntu-latest
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
python:
42+
[
43+
"3.7",
44+
"3.8",
45+
"3.9",
46+
"3.10",
47+
"3.11",
48+
"pypy-3.8",
49+
"pypy-3.9",
50+
]
51+
trino: ["latest"]
52+
sqlalchemy: ["~=1.4.0"]
53+
include:
54+
# Test with older Trino versions for backward compatibility
55+
- { python: "3.11", trino: "351", sqlalchemy: "~=1.4.0" } # first Trino version
56+
# Test with sqlalchemy 1.3
57+
- { python: "3.11", trino: "latest", sqlalchemy: "~=1.3.0" }
58+
# Test with sqlalchemy 2.0
59+
- {
60+
python: "3.11",
61+
trino: "latest",
62+
sqlalchemy: "~=2.0.0b4",
63+
}
64+
env:
65+
TRINO_VERSION: "${{ matrix.trino }}"
66+
steps:
67+
- uses: actions/checkout@v3
68+
- uses: actions/setup-python@v4
69+
with:
70+
python-version: ${{ matrix.python }}
71+
- name: Install dependencies
72+
run: |
73+
sudo apt-get update
74+
sudo apt-get install libkrb5-dev
75+
pip install .[tests] sqlalchemy${{ matrix.sqlalchemy }}
76+
- name: Run tests
77+
run: |
78+
pytest -s tests/

setup.py

Lines changed: 2 additions & 2 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.
@@ -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)