Skip to content

Commit 6d497de

Browse files
committed
test: Adapt to SQLAlchemy 2.0
Signed-off-by: Ferenc Géczi <[email protected]>
1 parent 67a6289 commit 6d497de

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tests/clients/test_sqlalchemy.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from instana.singletons import tracer
1010
from sqlalchemy.orm import sessionmaker
1111
from sqlalchemy.exc import OperationalError
12-
from sqlalchemy.ext.declarative import declarative_base
13-
from sqlalchemy import Column, Integer, String, create_engine
12+
from sqlalchemy.orm import declarative_base
13+
from sqlalchemy import Column, Integer, String, create_engine, text
1414

1515

1616
engine = create_engine("postgresql://%s:%s@%s/%s" % (testenv['postgresql_user'], testenv['postgresql_pw'],
@@ -90,8 +90,8 @@ def test_transaction(self):
9090
result = None
9191
with tracer.start_active_span('test'):
9292
with engine.begin() as connection:
93-
result = connection.execute("select 1")
94-
result = connection.execute("select (name, fullname, password) from churchofstan where name='doesntexist'")
93+
result = connection.execute(text("select 1"))
94+
result = connection.execute(text("select (name, fullname, password) from churchofstan where name='doesntexist'"))
9595

9696
spans = self.recorder.queued_spans()
9797
self.assertEqual(3, len(spans))
@@ -146,7 +146,7 @@ def test_transaction(self):
146146
def test_error_logging(self):
147147
with tracer.start_active_span('test'):
148148
try:
149-
self.session.execute("htVwGrCwVThisIsInvalidSQLaw4ijXd88")
149+
self.session.execute(text("htVwGrCwVThisIsInvalidSQLaw4ijXd88"))
150150
self.session.commit()
151151
except:
152152
pass
@@ -204,7 +204,8 @@ def test_error_before_tracing(self):
204204
r'\(psycopg2.OperationalError\) connection .* failed.*'
205205
) as context_manager:
206206
engine = create_engine(invalid_connection_url)
207-
version, = engine.execute("select version()").fetchone()
207+
with engine.connect() as connection:
208+
version, = connection.execute(text("select version()")).fetchone()
208209

209210
the_exception = context_manager.exception
210211
self.assertFalse(the_exception.connection_invalidated)

0 commit comments

Comments
 (0)