Skip to content

Commit 49f6ca3

Browse files
committed
test: fix sqlalchemy deprecated execute param
1 parent 4ada3fe commit 49f6ca3

6 files changed

Lines changed: 27 additions & 18 deletions

File tree

_appmap/test/test_sqlalchemy.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
MetaData,
1111
String,
1212
Table,
13+
text,
1314
create_engine,
1415
)
1516

@@ -23,7 +24,10 @@
2324
class TestSQLAlchemy(AppMapTestBase):
2425
@staticmethod
2526
def test_sql_capture(connection, events):
26-
connection.execute("SELECT 1")
27+
# Passing a string to execute is deprecated in 1.4
28+
# and removed in 2.0. We wrap it with text().
29+
# https://docs.sqlalchemy.org/en/14/core/connections.html#sqlalchemy.engine.Connection.execute
30+
connection.execute(text("SELECT 1"))
2731
assert events[0].sql_query == DictIncluding(
2832
{"sql": "SELECT 1", "database_type": "sqlite"}
2933
)
@@ -38,25 +42,27 @@ def test_capture_ddl(events, schema):
3842
assert "CREATE TABLE addresses" in events[-2].sql_query["sql"]
3943

4044
# pylint: disable=unused-argument
41-
def test_capture_insert(self, connection, schema, events):
45+
def test_capture_insert(self, engine, schema, events):
4246
ins = self.users.insert().values(name="jack", fullname="Jack Jones")
43-
connection.execute(ins)
47+
with engine.begin() as conn:
48+
conn.execute(ins)
4449
assert (
4550
events[-2].sql_query["sql"]
4651
== "INSERT INTO users (name, fullname) VALUES (?, ?)"
4752
)
4853

4954
# pylint: disable=unused-argument
50-
def test_capture_insert_many(self, connection, schema, events):
51-
connection.execute(
52-
self.addresses.insert(),
53-
[
54-
{"user_id": 1, "email_address": "jack@yahoo.com"},
55-
{"user_id": 1, "email_address": "jack@msn.com"},
56-
{"user_id": 2, "email_address": "www@www.org"},
57-
{"user_id": 2, "email_address": "wendy@aol.com"},
58-
],
59-
)
55+
def test_capture_insert_many(self, engine, schema, events):
56+
with engine.begin() as conn:
57+
conn.execute(
58+
self.addresses.insert(),
59+
[
60+
{"user_id": 1, "email_address": "jack@yahoo.com"},
61+
{"user_id": 1, "email_address": "jack@msn.com"},
62+
{"user_id": 2, "email_address": "www@www.org"},
63+
{"user_id": 2, "email_address": "wendy@aol.com"},
64+
],
65+
)
6066
assert (
6167
events[-2].sql_query["sql"]
6268
== "-- 4 times\nINSERT INTO addresses (user_id, email_address) VALUES (?, ?)"

appmap/sqlalchemy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@event.listens_for(Engine, "before_cursor_execute")
1616
# pylint: disable=too-many-arguments,unused-argument
1717
def capture_sql_call(conn, cursor, statement, parameters, context, executemany):
18-
"""Capture SQL query callinto appmap."""
18+
"""Capture SQL query call into appmap."""
1919
if is_instrumentation_disabled():
2020
# We must be in the middle of fetching object representation.
2121
# Don't record this query in the appmap.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ packaging = ">=19.0"
5151
# install it and the rest of the dev dependencies.
5252

5353
[tool.poetry.group.dev.dependencies]
54-
SQLAlchemy = "^1.4.11"
5554
Twisted = "^22.4.0"
5655
asgiref = "^3.7.2"
5756
black = "^24.2.0"

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ django
44
flask >=2, <= 3
55
pytest-django<4.8
66
fastapi
7-
httpx
7+
httpx
8+
sqlalchemy

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
django ~= 3.2
22
pytest-django < 4.8
3+
sqlalchemy < 2.0

tox.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
isolated_build = true
33
# The *-web environments test the latest versions of Django and Flask with the full test suite. For
44
# older version of the web frameworks, just run the tests that are specific to them.
5-
envlist = py3{8,9,10,11,12}-{web,django3,flask2}
5+
envlist = py3{8,9,10,11,12}-{web,django3,flask2,sqlalchemy1}
66

77
[testenv]
88
allowlist_externals =
@@ -13,16 +13,18 @@ deps=
1313
poetry
1414
web: Django >=4.0, <5.0
1515
web: Flask >=3.0
16+
web: sqlalchemy >=2.0, <3.0
1617
flask2: Flask >= 2.0, <3.0
1718
django3: Django >=3.2, <4.0
18-
19+
sqlalchemy1: sqlalchemy >=1.4.11, <2.0
1920

2021
commands =
2122
poetry install -v
2223
py310-web: poetry run pylint -j 0 appmap _appmap
2324
web: poetry run appmap-python {posargs:pytest}
2425
django3: poetry run appmap-python pytest _appmap/test/test_django.py
2526
flask2: poetry run appmap-python pytest _appmap/test/test_flask.py
27+
sqlalchemy1: poetry run appmap-python pytest _appmap/test/test_sqlalchemy.py
2628

2729
[testenv:vendoring]
2830
skip_install = True

0 commit comments

Comments
 (0)