Skip to content

Commit d31297c

Browse files
committed
Run pformat before adding to seen_layers
Fixes problems where repr may render more templates
1 parent 769e905 commit d31297c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

debug_toolbar/panels/templates/panel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,16 @@ def _store_template_info(self, sender, **kwargs):
141141
temp_layer[key] = value
142142
finally:
143143
recording(True)
144+
# Execute pformat first - if for some reason pformat/repr
145+
# causes more templates to be rendered, seen/pformat layers
146+
# will still be consistent
147+
pformatted = pformat(temp_layer)
144148
# Refs GitHub issue #910
145149
# If we've not seen the layer before then we will add it
146150
# so that if we see it again we can skip formatting it.
147151
self.seen_layers.append(key_values)
148152
# Note: this *ought* to be len(...) - 1 but let's be safe.
149153
index = self.seen_layers.index(key_values)
150-
pformatted = pformat(temp_layer)
151154
# Note: this *ought* to be len(...) - 1 but let's be safe.
152155
self.pformat_layers.insert(index, pformatted)
153156
context_list.append(pformatted)

0 commit comments

Comments
 (0)