Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SQL_TOKEN_GROUPING setting to control token grouping in SQL panel #1404

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion debug_toolbar/panels/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.utils.html import escape
from sqlparse import tokens as T

from debug_toolbar import settings as dt_settings


class BoldKeywordFilter:
"""sqlparse filter to bold SQL keywords"""
Expand Down Expand Up @@ -31,7 +33,8 @@ def reformat_sql(sql, with_toggle=False):

def parse_sql(sql, aligned_indent=False):
stack = sqlparse.engine.FilterStack()
stack.enable_grouping()
if dt_settings.get_config()["SQL_TOKEN_GROUPING"]:
stack.enable_grouping()
if aligned_indent:
stack.stmtprocess.append(
sqlparse.filters.AlignedIndentFilter(char="&nbsp;", n="<br/>")
Expand Down
1 change: 1 addition & 0 deletions debug_toolbar/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"SHOW_TEMPLATE_CONTEXT": True,
"SKIP_TEMPLATE_PREFIXES": ("django/forms/widgets/", "admin/widgets/"),
"SQL_WARNING_THRESHOLD": 500, # milliseconds
"SQL_TOKEN_GROUPING": True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep in line with the rest of the settings, this should likely be either ENABLE_SQL_TOKEN_GROUPING or SQL_ENABLE_TOKEN_GROUPING. @matthiask opinions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request which introduced the code in question was this one: #1116

I don't think anyone understands what "token grouping" should be in this context. Maybe something like PRETTIFY_SQL would describe the intent better and allow us to disable or enable additional prettification features with one setting. The NOUN_VERB format seems to be used with many settings, e.g. "show template context", "enable stacktraces" etc.

}


Expand Down
10 changes: 10 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ Panel options
The SQL panel highlights queries that took more that this amount of time,
in milliseconds, to execute.

* ``SQL_TOKEN_GROUPING``

Default: ``True``

Panel: SQL

Controls SQL token grouping.
When set to ``True``, it might cause render slowdowns
when a view make long SQL textual queries.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the documentation should briefly explain what grouping of SQL tokens means so that the developer understands what this setting does when it's set to True besides the possible performance impact.


Here's what a slightly customized toolbar configuration might look like::

# This example is unlikely to be appropriate for your project.
Expand Down