Skip to content

Commit e682f3f

Browse files
fix
1 parent 59ffaa7 commit e682f3f

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

debug_toolbar/panels/profiling.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ def generate_stats(self, request, response):
205205
# If writing to the file fails, we don't want to break the
206206
# whole page.
207207

208-
root_func = cProfile.label(super().process_request.__code__)
208+
code = super().process_request.__code__
209+
root_func = (code.co_filename, code.co_firstlineno, code.co_name)
209210
if root_func in self.stats.stats:
210211
root = FunctionCall(self.stats, root_func, depth=0)
211212
func_list = []

tests/panels/test_profiling.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def test_generate_stats_no_profiler(self):
8484
self.assertIsNone(self.panel.generate_stats(self.request, response))
8585

8686
def test_generate_stats_signed_path(self):
87-
with tempfile.TemporaryDirectory() as tmpdir:
87+
tmpdir = tempfile.mkdtemp()
88+
try:
8889
with self.settings(DEBUG_TOOLBAR_CONFIG={"PROFILER_PROFILE_ROOT": tmpdir}):
8990
response = self.panel.process_request(self.request)
9091
self.panel.generate_stats(self.request, response)
@@ -93,6 +94,8 @@ def test_generate_stats_signed_path(self):
9394
# Check that it's a valid signature
9495
filename = signing.loads(path)
9596
self.assertTrue(filename.endswith(".prof"))
97+
finally:
98+
shutil.rmtree(tmpdir)
9699

97100
def test_generate_stats_no_root(self):
98101
response = self.panel.process_request(self.request)
@@ -114,7 +117,8 @@ def test_generate_stats_no_root_func(self):
114117
@unittest.mock.patch("cProfile.Profile.dump_stats")
115118
def test_generate_stats_oserror(self, mock_dump_stats):
116119
mock_dump_stats.side_effect = OSError
117-
with tempfile.TemporaryDirectory() as tmpdir:
120+
tmpdir = tempfile.mkdtemp()
121+
try:
118122
with self.settings(DEBUG_TOOLBAR_CONFIG={"PROFILER_PROFILE_ROOT": tmpdir}):
119123
response = self.panel.process_request(self.request)
120124
with self.assertLogs(
@@ -124,6 +128,8 @@ def test_generate_stats_oserror(self, mock_dump_stats):
124128
self.assertIn("Failed to dump profiling stats", cm.output[0])
125129
# Ensure prof_file_path is not set/updated if dump fails
126130
self.assertFalse(hasattr(self.panel, "prof_file_path"))
131+
finally:
132+
shutil.rmtree(tmpdir)
127133

128134

129135
@override_settings(

0 commit comments

Comments
 (0)