|
9 | 9 | from instana.singletons import tracer |
10 | 10 | from sqlalchemy.orm import sessionmaker |
11 | 11 | 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 |
14 | 14 |
|
15 | 15 |
|
16 | 16 | engine = create_engine("postgresql://%s:%s@%s/%s" % (testenv['postgresql_user'], testenv['postgresql_pw'], |
@@ -90,8 +90,8 @@ def test_transaction(self): |
90 | 90 | result = None |
91 | 91 | with tracer.start_active_span('test'): |
92 | 92 | 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'")) |
95 | 95 |
|
96 | 96 | spans = self.recorder.queued_spans() |
97 | 97 | self.assertEqual(3, len(spans)) |
@@ -146,7 +146,7 @@ def test_transaction(self): |
146 | 146 | def test_error_logging(self): |
147 | 147 | with tracer.start_active_span('test'): |
148 | 148 | try: |
149 | | - self.session.execute("htVwGrCwVThisIsInvalidSQLaw4ijXd88") |
| 149 | + self.session.execute(text("htVwGrCwVThisIsInvalidSQLaw4ijXd88")) |
150 | 150 | self.session.commit() |
151 | 151 | except: |
152 | 152 | pass |
@@ -204,7 +204,8 @@ def test_error_before_tracing(self): |
204 | 204 | r'\(psycopg2.OperationalError\) connection .* failed.*' |
205 | 205 | ) as context_manager: |
206 | 206 | 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() |
208 | 209 |
|
209 | 210 | the_exception = context_manager.exception |
210 | 211 | self.assertFalse(the_exception.connection_invalidated) |
0 commit comments