Skip to content

Commit a4585d8

Browse files
authored
Add test documenting missing PEP249 alerts for connection stored in self attribute
1 parent 7795884 commit a4585d8

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

  • python/ql/test/library-tests/frameworks/hdbcli

python/ql/test/library-tests/frameworks/hdbcli/pep249.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,31 @@
77
cursor.executemany("some sql", (42,)) # $ getSql="some sql"
88

99
cursor.close()
10+
11+
12+
# Connection stored in a class attribute (`self._conn`) and used in another method.
13+
#
14+
# This is currently NOT detected: the `Connection::instance()`/`execute()` predicates in
15+
# PEP249.qll are based on type tracking, which cannot follow a value that is stored into a
16+
# `self` attribute in one method and read from a `self` attribute in another method (see the
17+
# `MISSING` markers below). Regular (global) data flow handles this case correctly, so the
18+
# limitation is specific to the type-tracking-based modeling.
19+
class Database:
20+
def __init__(self):
21+
self._conn = dbapi.connect(address="hostname", port=300, user="username")
22+
23+
def get_connection(self):
24+
return self._conn
25+
26+
def run_via_getter(self):
27+
conn = self.get_connection()
28+
cursor = conn.cursor()
29+
cursor.execute("getter sql") # $ MISSING: getSql="getter sql"
30+
31+
def run_direct(self):
32+
self._conn.execute("direct sql") # $ MISSING: getSql="direct sql"
33+
34+
35+
db = Database()
36+
db.run_via_getter()
37+
db.run_direct()

0 commit comments

Comments
 (0)