Skip to content

stacktrace: include number of hidden frames #1095

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion debug_toolbar/panels/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def wrapped(self, *args, **kwargs):
if dt_settings.get_config()['ENABLE_STACKTRACES']:
stacktrace = tidy_stacktrace(reversed(get_stack()))
else:
stacktrace = []
stacktrace = ([], 0)

template_info = get_template_info()
cache_called.send(sender=self.__class__, time_taken=t,
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/panels/sql/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _record(self, method, sql, params):
if dt_settings.get_config()['ENABLE_STACKTRACES']:
stacktrace = tidy_stacktrace(reversed(get_stack()))
else:
stacktrace = []
stacktrace = ([], 0)
_params = ''
try:
_params = json.dumps([self._decode(p) for p in params])
Expand Down
3 changes: 3 additions & 0 deletions debug_toolbar/static/debug_toolbar/css/toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,9 @@
#djDebug .djdt-stack span.djdt-code {
font-weight: normal;
}
#djDebug .djdt-stack span.djdt-hidden_count {
font-weight: normal;
}

#djDebug .djdt-width-20 {
width: 20%;
Expand Down
13 changes: 8 additions & 5 deletions debug_toolbar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@ def omit_path(path):

def tidy_stacktrace(stack):
"""
Clean up stacktrace and remove all entries that:
1. Are part of Django (except contrib apps)
2. Are part of socketserver (used by Django's dev server)
3. Are the last entry (which is part of our stacktracing code)
Clean up stacktrace and remove entries according to HIDE_IN_STACKTRACES.

``stack`` should be a list of frame tuples from ``inspect.stack()``
"""
trace = []
hidden_count = 0
for frame, path, line_no, func_name, text in (f[:5] for f in stack):
if omit_path(os.path.realpath(path)):
hidden_count += 1
continue
text = (''.join(force_text(t) for t in text)).strip() if text else ''
trace.append((path, line_no, func_name, text))
return trace
return trace, hidden_count


def render_stacktrace(trace):
stacktrace = []
trace, hidden_count = trace
for frame in trace:
params = (escape(v) for v in chain(frame[0].rsplit(os.path.sep, 1), frame[1:]))
params_dict = {six.text_type(idx): v for idx, v in enumerate(params)}
Expand All @@ -83,6 +83,9 @@ def render_stacktrace(trace):
except KeyError:
# This frame doesn't have the expected format, so skip it and move on to the next one
continue
if hidden_count:
stacktrace.append('<span class="djdt-hidden_count">'
'%d hidden frames.</span>' % hidden_count)
return mark_safe('\n'.join(stacktrace))


Expand Down
2 changes: 1 addition & 1 deletion tests/panels/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_disable_stacktraces(self):
self.assertTrue('stacktrace' in query[1])

# ensure the stacktrace is empty
self.assertEqual([], query[1]['stacktrace'])
self.assertEqual(([], 0), query[1]['stacktrace'])

@override_settings(DEBUG=True, TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand Down