Skip to content

Commit 5360a2b

Browse files
committed
Properly disable instrumentation for the template panel.
It's important to disconnect the signal at the end of a request because the toolbar now stores panels for past request. Fix #491 (presumably).
1 parent dbed3e7 commit 5360a2b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

debug_toolbar/panels/templates/panel.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,8 @@ class TemplatesPanel(Panel):
8181
def __init__(self, *args, **kwargs):
8282
super(TemplatesPanel, self).__init__(*args, **kwargs)
8383
self.templates = []
84-
template_rendered.connect(self._store_template_info)
8584

8685
def _store_template_info(self, sender, **kwargs):
87-
if not self.enabled:
88-
return
89-
9086
template, context = kwargs['template'], kwargs['context']
9187

9288
# Skip templates that we are generating through the debug toolbar.
@@ -157,6 +153,12 @@ def get_urls(cls):
157153
url(r'^template_source/$', 'template_source', name='template_source'),
158154
)
159155

156+
def enable_instrumentation(self):
157+
template_rendered.connect(self._store_template_info)
158+
159+
def disable_instrumentation(self):
160+
template_rendered.disconnect(self._store_template_info)
161+
160162
def process_response(self, request, response):
161163
template_context = []
162164
for template_data in self.templates:

tests/panels/test_template.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ class TemplatesPanelTestCase(BaseTestCase):
1515
def setUp(self):
1616
super(TemplatesPanelTestCase, self).setUp()
1717
self.panel = self.toolbar.get_panel_by_id('TemplatesPanel')
18+
self.panel.enable_instrumentation()
1819
self.sql_panel = self.toolbar.get_panel_by_id('SQLPanel')
1920
self.sql_panel.enable_instrumentation()
2021

2122
def tearDown(self):
2223
self.sql_panel.disable_instrumentation()
24+
self.panel.disable_instrumentation()
2325
super(TemplatesPanelTestCase, self).tearDown()
2426

2527
def test_queryset_hook(self):

0 commit comments

Comments
 (0)