Skip to content

Commit 0256163

Browse files
committed
panels(templates): avoid evaluating LazyObject
LazyObject is typically used for something expensive to evaluate, so avoid evaluating it just for showing it in the debug toolbar.
1 parent 199c2b3 commit 0256163

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

debug_toolbar/panels/templates/panel.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,15 @@ def _store_template_info(self, sender, **kwargs):
9696
if pformatted is None:
9797
temp_layer = {}
9898
for key, value in context_layer.items():
99+
# Do not force evaluating LazyObject
100+
if hasattr(value, "_wrapped"):
101+
# SimpleLazyObject has __repr__ which includes actual value
102+
# if it has been already evaluated
103+
temp_layer[key] = repr(value)
99104
# Replace any request elements - they have a large
100105
# Unicode representation and the request data is
101106
# already made available from the Request panel.
102-
if isinstance(value, http.HttpRequest):
107+
elif isinstance(value, http.HttpRequest):
103108
temp_layer[key] = "<<request>>"
104109
# Replace the debugging sql_queries element. The SQL
105110
# data is already made available from the SQL panel.

0 commit comments

Comments
 (0)