mirror of
https://github.com/pallets-eco/flask-debugtoolbar.git
synced 2025-12-30 18:19:31 -06:00
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
This commit is contained in:
@@ -6,10 +6,15 @@ except ImportError:
|
||||
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():
|
||||
|
||||
Reference in New Issue
Block a user