|
21 | 21 | from threading import Lock
|
22 | 22 |
|
23 | 23 | import sqlalchemy
|
24 |
| -from flask import _app_ctx_stack, abort, current_app, g, request |
| 24 | +from flask import _app_ctx_stack, abort, current_app, request |
25 | 25 | from flask.signals import Namespace
|
26 | 26 | from sqlalchemy import event, inspect, orm
|
27 | 27 | from sqlalchemy.engine.url import make_url
|
@@ -257,10 +257,12 @@ def after_cursor_execute(
|
257 | 257 | self, conn, cursor, statement, parameters, context, executemany
|
258 | 258 | ):
|
259 | 259 | if current_app:
|
260 |
| - if 'sqlalchemy_queries' not in g: |
261 |
| - g.sqlalchemy_queries = [] |
| 260 | + try: |
| 261 | + queries = _app_ctx_stack.top.sqlalchemy_queries |
| 262 | + except AttributeError: |
| 263 | + queries = _app_ctx_stack.top.sqlalchemy_queries = [] |
262 | 264 |
|
263 |
| - g.sqlalchemy_queries.append(_DebugQueryTuple(( |
| 265 | + queries.append(_DebugQueryTuple(( |
264 | 266 | statement, parameters, context._query_start_time, _timer(),
|
265 | 267 | _calling_context(self.app_package)
|
266 | 268 | )))
|
@@ -298,7 +300,7 @@ def get_debug_queries():
|
298 | 300 | query was issued. The exact format is undefined so don't try
|
299 | 301 | to reconstruct filename or function name.
|
300 | 302 | """
|
301 |
| - return g.get('sqlalchemy_queries', ()) |
| 303 | + return getattr(_app_ctx_stack.top, 'sqlalchemy_queries', []) |
302 | 304 |
|
303 | 305 |
|
304 | 306 | class Pagination(object):
|
|
0 commit comments