Skip to content

Commit 35c9aff

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix NotImplementedError in dbcounter on SQLA 2.x"
2 parents 3894077 + f834f9a commit 35c9aff

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes a NotImplementedError when using the dbcounter SQLAlchemy plugin on
5+
SQLAlchemy 2.x.

tools/dbcounter/dbcounter.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def __init__(self, url, kwargs):
4040
self.queue = queue.Queue()
4141
self.thread = None
4242

43+
def update_url(self, url):
44+
return url.difference_update_query(["dbcounter"])
45+
4346
def engine_created(self, engine):
4447
"""Hook the engine creation process.
4548
@@ -77,12 +80,12 @@ def _log_event(self, conn, cursor, statement, parameters, context,
7780
def do_incr(self, db, op, count):
7881
"""Increment the counter for (db,op) by count."""
7982

80-
query = ('INSERT INTO queries (db, op, count) '
81-
' VALUES (%s, %s, %s) '
82-
' ON DUPLICATE KEY UPDATE count=count+%s')
83+
query = sqlalchemy.text('INSERT INTO queries (db, op, count) '
84+
' VALUES (:db, :op, :count) '
85+
' ON DUPLICATE KEY UPDATE count=count+:count')
8386
try:
8487
with self.engine.begin() as conn:
85-
r = conn.execute(query, (db, op, count, count))
88+
r = conn.execute(query, {'db': db, 'op': op, 'count': count})
8689
except Exception as e:
8790
LOG.error('Failed to account for access to database %r: %s',
8891
db, e)

0 commit comments

Comments
 (0)