From 025616304c172d8250809c571de494eab753e796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 19 Sep 2023 08:12:55 +0200 Subject: [PATCH] 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. --- debug_toolbar/panels/templates/panel.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/panels/templates/panel.py b/debug_toolbar/panels/templates/panel.py index 72565f016..e9a27130f 100644 --- a/debug_toolbar/panels/templates/panel.py +++ b/debug_toolbar/panels/templates/panel.py @@ -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] = "<>" # Replace the debugging sql_queries element. The SQL # data is already made available from the SQL panel.