Skip to content

Commit

Permalink
panels(templates): avoid evaluating LazyObject
Browse files Browse the repository at this point in the history
LazyObject is typically used for something expensive to evaluate, so avoid evaluating it just for showing it in the debug toolbar.
  • Loading branch information
nijel committed Sep 19, 2023
1 parent 199c2b3 commit 0256163
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion debug_toolbar/panels/templates/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,15 @@ def _store_template_info(self, sender, **kwargs):
if pformatted is None:
temp_layer = {}
for key, value in context_layer.items():
# Do not force evaluating LazyObject
if hasattr(value, "_wrapped"):
# SimpleLazyObject has __repr__ which includes actual value
# if it has been already evaluated
temp_layer[key] = repr(value)
# Replace any request elements - they have a large
# Unicode representation and the request data is
# already made available from the Request panel.
if isinstance(value, http.HttpRequest):
elif isinstance(value, http.HttpRequest):
temp_layer[key] = "<<request>>"
# Replace the debugging sql_queries element. The SQL
# data is already made available from the SQL panel.
Expand Down

0 comments on commit 0256163

Please sign in to comment.