Skip to content

Commit 4acf02f

Browse files
committed
Refs #910 - Thinking further on it. Using id() on the Context is probably not the wisest, as it is likely to mutate with pushes & pops during the course of renderings, which may add or remove keys which wouldn't be reflected in this re-use.
Doing the id() on the individual layers would work better, in this case, because pushes and pops don't mutate the underlying dict, just add new/remove existing ones.
1 parent 6154046 commit 4acf02f

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

debug_toolbar/panels/templates/panel.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ def _store_template_info(self, sender, **kwargs):
8787
# Refs #910
8888
# The same Context instance may be passed around a lot, so if we've
8989
# seen it before, just re-use the previous output.
90-
context_id = id(context)
91-
if context_id in self.seen_contexts:
92-
context_list = self.seen_contexts[context_id]
93-
else:
94-
context_list = []
95-
for context_layer in context.dicts:
90+
context_list = []
91+
for context_layer in context.dicts:
92+
context_layer_id = id(context_layer)
93+
if context_layer_id in self.seen_contexts:
94+
context_list.append(self.seen_contexts[context_layer_id])
95+
else:
9696
temp_layer = {}
9797
if hasattr(context_layer, 'items'):
9898
for key, value in context_layer.items():
@@ -134,15 +134,7 @@ def _store_template_info(self, sender, **kwargs):
134134
pass
135135
else:
136136
context_list.append(prettified_layer)
137-
# Refs GitHub issue #910
138-
# After Django introduced template based form widget rendering,
139-
# djdt has to collect and format far more contexts, many of which
140-
# are duplicates, and don't need formatting if we've already seen
141-
# the exact same context.
142-
# At this point, we know this is the first time we've seen and
143-
# collected the layers of this context, so we store the value into
144-
# a dictionary whose key is the id() of the Context instance.
145-
self.seen_contexts[context_id] = context_list
137+
self.seen_contexts[context_layer_id]= prettified_layer
146138

147139
kwargs['context'] = context_list
148140
kwargs['context_processors'] = getattr(context, 'context_processors', None)

0 commit comments

Comments
 (0)