From 9656a2cf3388226d630f3d6837c5fdfeee21667f Mon Sep 17 00:00:00 2001 From: Jonty Wareing Date: Wed, 20 Mar 2024 13:55:53 +0000 Subject: [PATCH] Fix SQLAlchemy recording warning for versions >= 3 Since SQLAlchemy 3.0 `SQLALCHEMY_RECORD_QUERIES` is no longer automatically enabled when Flask is running in debug or testing mode so the debug toolbar warning will never be shown. https://flask-sqlalchemy.palletsprojects.com/en/3.0.x/config/#flask_sqlalchemy.config.SQLALCHEMY_RECORD_QUERIES --- src/flask_debugtoolbar/panels/sqlalchemy.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/flask_debugtoolbar/panels/sqlalchemy.py b/src/flask_debugtoolbar/panels/sqlalchemy.py index 13211eb..59e17c7 100644 --- a/src/flask_debugtoolbar/panels/sqlalchemy.py +++ b/src/flask_debugtoolbar/panels/sqlalchemy.py @@ -6,10 +6,15 @@ else: try: from flask_sqlalchemy.record_queries import get_recorded_queries + debug_enables_record_queries = False except ImportError: # For flask_sqlalchemy < 3.0.0 from flask_sqlalchemy import get_debug_queries as get_recorded_queries + # flask_sqlalchemy < 3.0.0 automatically enabled + # SQLALCHEMY_RECORD_QUERIES in debug or test mode + debug_enables_record_queries = True + location_property = 'context' else: location_property = 'location' @@ -62,7 +67,10 @@ def extension_used(): def recording_enabled(): - return (current_app.debug or current_app.config.get('SQLALCHEMY_RECORD_QUERIES')) + return ( + (debug_enables_record_queries and current_app.debug) or + current_app.config.get('SQLALCHEMY_RECORD_QUERIES') + ) def is_available():