Skip to content

Commit c33ce08

Browse files
committed
Stop sharing unsafely a context dict across threads.
Panels that need to share data with other panels shall do it through the record_stats / get_stats API. Statistics are automatically pushed to the template context. Fix #450.
1 parent c12de85 commit c33ce08

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

debug_toolbar/panels/__init__.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@ class Panel(object):
99
"""
1010
Base class for panels.
1111
"""
12-
13-
# We'll maintain a local context instance so we can expose our template
14-
# context variables to panels which need them. (But see issue #450.)
15-
context = {}
16-
17-
# Private panel methods
18-
19-
def __init__(self, toolbar, context={}):
12+
def __init__(self, toolbar):
2013
self.toolbar = toolbar
21-
self.context.update(context)
14+
15+
# Private panel properties
2216

2317
@property
2418
def panel_id(self):
@@ -81,9 +75,7 @@ def content(self):
8175
template's context.
8276
"""
8377
if self.has_content:
84-
context = self.context.copy()
85-
context.update(self.get_stats())
86-
return render_to_string(self.template, context)
78+
return render_to_string(self.template, self.get_stats())
8779

8880
# URLs for panel-specific views
8981

debug_toolbar/panels/timer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ def content(self):
4545
(_('Elapsed time'), _('%(total_time)0.3f msec') % stats),
4646
(_('Context switches'), _('%(vcsw)d voluntary, %(ivcsw)d involuntary') % stats),
4747
)
48-
context = self.context.copy()
49-
context.update({'rows': rows})
50-
return render_to_string(self.template, context)
48+
return render_to_string(self.template, {'rows': rows})
5149

5250
def process_request(self, request):
5351
self._start_time = time.time()

debug_toolbar/toolbar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ class DebugToolbar(object):
2020
def __init__(self, request):
2121
self.request = request
2222
self.config = dt_settings.CONFIG.copy()
23-
self.template_context = {'toolbar': self}
2423
self._panels = SortedDict()
2524
for panel_class in self.get_panel_classes():
26-
panel_instance = panel_class(self, context=self.template_context)
25+
panel_instance = panel_class(self)
2726
self._panels[panel_instance.panel_id] = panel_instance
2827
self.stats = {}
2928
self.store_id = None
@@ -58,8 +57,7 @@ def render_toolbar(self):
5857
"""
5958
if not self.should_render_panels():
6059
self.store()
61-
context = self.template_context.copy()
62-
return render_to_string('debug_toolbar/base.html', context)
60+
return render_to_string('debug_toolbar/base.html', {'toolbar': self})
6361

6462
# Handle storing toolbars in memory and fetching them later on
6563

0 commit comments

Comments
 (0)