Skip to content

Commit 9656a2c

Browse files
committed
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
1 parent 9b63ad1 commit 9656a2c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/flask_debugtoolbar/panels/sqlalchemy.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
else:
77
try:
88
from flask_sqlalchemy.record_queries import get_recorded_queries
9+
debug_enables_record_queries = False
910
except ImportError:
1011
# For flask_sqlalchemy < 3.0.0
1112
from flask_sqlalchemy import get_debug_queries as get_recorded_queries
1213

14+
# flask_sqlalchemy < 3.0.0 automatically enabled
15+
# SQLALCHEMY_RECORD_QUERIES in debug or test mode
16+
debug_enables_record_queries = True
17+
1318
location_property = 'context'
1419
else:
1520
location_property = 'location'
@@ -62,7 +67,10 @@ def extension_used():
6267

6368

6469
def recording_enabled():
65-
return (current_app.debug or current_app.config.get('SQLALCHEMY_RECORD_QUERIES'))
70+
return (
71+
(debug_enables_record_queries and current_app.debug) or
72+
current_app.config.get('SQLALCHEMY_RECORD_QUERIES')
73+
)
6674

6775

6876
def is_available():

0 commit comments

Comments
 (0)