From 4f0d75c94ca1acf0217990d67092f8a72a9cdef1 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 3 Sep 2024 16:22:51 -0500 Subject: Provide means to debug actual query run and params used. --- uploader/db_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/uploader/db_utils.py b/uploader/db_utils.py index 5b79762..d31e2c2 100644 --- a/uploader/db_utils.py +++ b/uploader/db_utils.py @@ -7,6 +7,7 @@ from typing import Any, Tuple, Iterator, Callable import MySQLdb as mdb from redis import Redis +from MySQLdb.cursors import Cursor from flask import current_app as app def parse_db_url(db_url) -> Tuple: @@ -43,3 +44,11 @@ def with_redis_connection(func: Callable[[Redis], Any]) -> Any: redisuri = app.config["REDIS_URL"] with Redis.from_url(redisuri, decode_responses=True) as rconn: return func(rconn) + + +def debug_query(cursor: Cursor): + """Debug the actual query run with MySQLdb""" + for attr in ("_executed", "statement", "_last_executed"): + if hasattr(cursor, attr): + logging.debug("MySQLdb QUERY: %s", getattr(cursor, attr)) + break -- cgit v1.2.3