Skip to content

Commit 86746c5

Browse files
authored
Merge pull request #1072 from blueyed/hidden-count
stacktrace: include number of hidden frames
2 parents 3927ad6 + 5bd7513 commit 86746c5

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

debug_toolbar/panels/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def wrapped(self, *args, **kwargs):
3232
if dt_settings.get_config()['ENABLE_STACKTRACES']:
3333
stacktrace = tidy_stacktrace(reversed(get_stack()))
3434
else:
35-
stacktrace = []
35+
stacktrace = ([], 0)
3636

3737
template_info = get_template_info()
3838
cache_called.send(sender=self.__class__, time_taken=t,

debug_toolbar/panels/sql/tracking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _record(self, method, sql, params):
113113
if dt_settings.get_config()['ENABLE_STACKTRACES']:
114114
stacktrace = tidy_stacktrace(reversed(get_stack()))
115115
else:
116-
stacktrace = []
116+
stacktrace = ([], 0)
117117
_params = ''
118118
try:
119119
_params = json.dumps([self._decode(p) for p in params])

debug_toolbar/static/debug_toolbar/css/toolbar.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,9 @@
642642
#djDebug .djdt-stack span.djdt-code {
643643
font-weight: normal;
644644
}
645+
#djDebug .djdt-stack span.djdt-hidden_count {
646+
font-weight: normal;
647+
}
645648

646649
@media print {
647650
#djDebug {

debug_toolbar/utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,24 @@ def omit_path(path):
5252

5353
def tidy_stacktrace(stack):
5454
"""
55-
Clean up stacktrace and remove all entries that:
56-
1. Are part of Django (except contrib apps)
57-
2. Are part of socketserver (used by Django's dev server)
58-
3. Are the last entry (which is part of our stacktracing code)
55+
Clean up stacktrace and remove entries according to HIDE_IN_STACKTRACES.
5956
6057
``stack`` should be a list of frame tuples from ``inspect.stack()``
6158
"""
6259
trace = []
60+
hidden_count = 0
6361
for frame, path, line_no, func_name, text in (f[:5] for f in stack):
6462
if omit_path(os.path.realpath(path)):
63+
hidden_count += 1
6564
continue
6665
text = (''.join(force_text(t) for t in text)).strip() if text else ''
6766
trace.append((path, line_no, func_name, text))
68-
return trace
67+
return trace, hidden_count
6968

7069

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

8891

tests/panels/test_sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def test_disable_stacktraces(self):
162162
self.assertTrue('stacktrace' in query[1])
163163

164164
# ensure the stacktrace is empty
165-
self.assertEqual([], query[1]['stacktrace'])
165+
self.assertEqual(([], 0), query[1]['stacktrace'])
166166

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

0 commit comments

Comments
 (0)