From 17dbfae3817af38a08091d7c70d5fe5433d55221 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/panels/templates/panel.py b/debug_toolbar/panels/templates/panel.py index 72565f016..17175ed03 100644 --- a/debug_toolbar/panels/templates/panel.py +++ b/debug_toolbar/panels/templates/panel.py @@ -96,10 +96,13 @@ 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"): + 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.