Skip to content

Commit 2acf518

Browse files
committed
Python: Model exec_driver_sql
1 parent fe143c7 commit 2acf518

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

python/ql/src/experimental/semmle/python/frameworks/SqlAlchemy.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ private module SqlAlchemy {
195195
override DataFlow::Node getSql() { result in [this.getArg(0), this.getArgByName("statement")] }
196196
}
197197

198+
/**
199+
* A call to `exec_driver_sql` on a SQLAlchemy Connection.
200+
* See
201+
* - https://docs.sqlalchemy.org/en/14/core/connections.html#sqlalchemy.engine.Connection.exec_driver_sql
202+
* - https://docs.sqlalchemy.org/en/14/core/future.html#sqlalchemy.future.Connection.exec_driver_sql
203+
*/
204+
private class SqlAlchemyExecDriverSqlCall extends DataFlow::MethodCallNode, SqlExecution::Range {
205+
SqlAlchemyExecDriverSqlCall() { this.calls(Connection::instance(), "exec_driver_sql") }
206+
207+
override DataFlow::Node getSql() { result in [this.getArg(0), this.getArgByName("statement")] }
208+
}
209+
198210
/**
199211
* A call to `scalar` on a SQLAlchemy Engine, Connection, or Session.
200212
* See

python/ql/test/experimental/library-tests/frameworks/sqlalchemy/new_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070

7171
# exec_driver_sql
72-
result = conn.exec_driver_sql(raw_sql) # $ MISSING: getSql=raw_sql
72+
result = conn.exec_driver_sql(raw_sql) # $ getSql=raw_sql
7373
assert result.fetchall() == [("FOO",)]
7474

7575
# construction by object
@@ -284,7 +284,7 @@ class For14(Base):
284284
result = conn.execute(statement=text_sql) # $ getSql=text_sql
285285
assert result.fetchall() == [("FOO",)]
286286

287-
result = conn.exec_driver_sql(raw_sql) # $ MISSING: getSql=raw_sql
287+
result = conn.exec_driver_sql(raw_sql) # $ getSql=raw_sql
288288
assert result.fetchall() == [("FOO",)]
289289

290290
raw_conn = conn.connection

0 commit comments

Comments
 (0)