Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions _appmap/test/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
MetaData,
String,
Table,
text,
create_engine,
)

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

# pylint: disable=unused-argument
def test_capture_insert(self, connection, schema, events):
def test_capture_insert(self, engine, schema, events):
ins = self.users.insert().values(name="jack", fullname="Jack Jones")
connection.execute(ins)
with engine.begin() as conn:
conn.execute(ins)
assert (
events[-2].sql_query["sql"]
== "INSERT INTO users (name, fullname) VALUES (?, ?)"
)

# pylint: disable=unused-argument
def test_capture_insert_many(self, connection, schema, events):
connection.execute(
self.addresses.insert(),
[
{"user_id": 1, "email_address": "jack@yahoo.com"},
{"user_id": 1, "email_address": "jack@msn.com"},
{"user_id": 2, "email_address": "www@www.org"},
{"user_id": 2, "email_address": "wendy@aol.com"},
],
)
def test_capture_insert_many(self, engine, schema, events):
with engine.begin() as conn:
conn.execute(
self.addresses.insert(),
[
{"user_id": 1, "email_address": "jack@yahoo.com"},
{"user_id": 1, "email_address": "jack@msn.com"},
{"user_id": 2, "email_address": "www@www.org"},
{"user_id": 2, "email_address": "wendy@aol.com"},
],
)
assert (
events[-2].sql_query["sql"]
== "-- 4 times\nINSERT INTO addresses (user_id, email_address) VALUES (?, ?)"
Expand Down
2 changes: 1 addition & 1 deletion appmap/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@event.listens_for(Engine, "before_cursor_execute")
# pylint: disable=too-many-arguments,unused-argument
def capture_sql_call(conn, cursor, statement, parameters, context, executemany):
"""Capture SQL query callinto appmap."""
"""Capture SQL query call into appmap."""
if is_instrumentation_disabled():
# We must be in the middle of fetching object representation.
# Don't record this query in the appmap.
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ packaging = ">=19.0"
# install it and the rest of the dev dependencies.

[tool.poetry.group.dev.dependencies]
SQLAlchemy = "^1.4.11"
Twisted = "^22.4.0"
asgiref = "^3.7.2"
black = "^24.2.0"
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ django
flask >=2, <= 3
pytest-django<4.8
fastapi
httpx
httpx
sqlalchemy
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
django ~= 3.2
pytest-django < 4.8
sqlalchemy < 2.0
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
isolated_build = true
# The *-web environments test the latest versions of Django and Flask with the full test suite. For
# older version of the web frameworks, just run the tests that are specific to them.
envlist = py3{8,9,10,11,12}-{web,django3,flask2}
envlist = py3{8,9,10,11,12}-{web,django3,flask2,sqlalchemy1}

[testenv]
allowlist_externals =
Expand All @@ -13,16 +13,18 @@ deps=
poetry
web: Django >=4.0, <5.0
web: Flask >=3.0
web: sqlalchemy >=2.0, <3.0
flask2: Flask >= 2.0, <3.0
django3: Django >=3.2, <4.0

sqlalchemy1: sqlalchemy >=1.4.11, <2.0

commands =
poetry install -v
py310-web: poetry run pylint -j 0 appmap _appmap
web: poetry run appmap-python {posargs:pytest}
django3: poetry run appmap-python pytest _appmap/test/test_django.py
flask2: poetry run appmap-python pytest _appmap/test/test_flask.py
sqlalchemy1: poetry run appmap-python pytest _appmap/test/test_sqlalchemy.py

[testenv:vendoring]
skip_install = True
Expand Down