Skip to content

Commit 8b505a1

Browse files
authored
Support for SQLAlchemy 2.0 (#2200)
Make sure our SQLAlchemy integration works with SQLAlchemy 1.4 and 2.0.
1 parent 52eaeba commit 8b505a1

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

tests/integrations/sqlalchemy/test_sqlalchemy.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from sqlalchemy.exc import IntegrityError
66
from sqlalchemy.ext.declarative import declarative_base
77
from sqlalchemy.orm import relationship, sessionmaker
8+
from sqlalchemy import text
89

910
from sentry_sdk import capture_message, start_transaction, configure_scope
1011
from sentry_sdk.consts import SPANDATA
@@ -152,7 +153,7 @@ def test_long_sql_query_preserved(sentry_init, capture_events):
152153
engine = create_engine("sqlite:///:memory:")
153154
with start_transaction(name="test"):
154155
with engine.connect() as con:
155-
con.execute(" UNION ".join("SELECT {}".format(i) for i in range(100)))
156+
con.execute(text(" UNION ".join("SELECT {}".format(i) for i in range(100))))
156157

157158
(event,) = events
158159
description = event["spans"][0]["description"]
@@ -180,7 +181,9 @@ def processor(event, hint):
180181
with start_transaction(name="test"):
181182
with engine.connect() as con:
182183
for _ in range(1500):
183-
con.execute(" UNION ".join("SELECT {}".format(i) for i in range(100)))
184+
con.execute(
185+
text(" UNION ".join("SELECT {}".format(i) for i in range(100)))
186+
)
184187

185188
(event,) = events
186189

@@ -218,4 +221,4 @@ def test_engine_name_not_string(sentry_init):
218221
engine.dialect.name = b"sqlite"
219222

220223
with engine.connect() as con:
221-
con.execute("SELECT 0")
224+
con.execute(text("SELECT 0"))

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ envlist =
147147
{py3.8,py3.9,py3.10,py3.11}-starlite
148148

149149
# SQL Alchemy
150-
{py2.7,py3.7,py3.8,py3.9,py3.10,py3.11}-sqlalchemy-v{1.2,1.3}
150+
{py2.7,py3.7,py3.8,py3.9,py3.10,py3.11}-sqlalchemy-v{1.2,1.3,1.4}
151+
{py3.7,py3.8,py3.9,py3.10,py3.11}-sqlalchemy-v{2.0}
151152

152153
# Tornado
153154
{py3.7,py3.8,py3.9}-tornado-v{5}
@@ -426,6 +427,8 @@ deps =
426427
# SQLAlchemy
427428
sqlalchemy-v1.2: sqlalchemy>=1.2,<1.3
428429
sqlalchemy-v1.3: sqlalchemy>=1.3,<1.4
430+
sqlalchemy-v1.4: sqlalchemy>=1.4,<2.0
431+
sqlalchemy-v2.0: sqlalchemy>=2.0,<2.1
429432

430433
# Tornado
431434
tornado-v5: tornado>=5,<6

0 commit comments

Comments
 (0)