connection queries_log when DEBUG is False

68 views
Skip to first unread message

Dan Davis

unread,
Jul 8, 2020, 7:03:48 PM7/8/20
to Django users
This has to do with Django internals, but is nonetheless a user question.

Various packages force_debug_cursor as illustrated in  https://www.webucator.com/blog/2015/08/python-clocks-explained/.
Other packages monkey patch the cursor wrapper to be used.

Does Django clear connection.queries_log after each request, or only if the connection is cleaned up?

Thanks, anyone,

-Dan

Dan Davis

unread,
Jul 8, 2020, 7:07:06 PM7/8/20
to Django users
Answering my own question:

The queries_log is cleared when Django begins processing a new request in django/db/__init__.py:

# Register an event to reset saved queries when a Django request is started.
def reset_queries(**kwargs):
    for conn in connections.all():
        conn.queries_log.clear()


signals.request_started.connect(reset_queries)
Reply all
Reply to author
Forward
0 new messages