WIP - template panel context issues #1076
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As I've now encountered an issue myself where the #910 changes caused problems, possibly related to some of the others, probably I should try and fix them all up.
As a short reminder, after template based widgets came along, and before #942 landed, I tried to ensure the number of calls to
pprint.pformat
was kept to a minimum, as it is an expensive calculation (#933).In doing so, the call changed from:
try: ... pformat(value); except: ...
to useforce_text
instead ofpformat
. This was, in hindsight, a mistake, mostly around usages ofForm
instances.Because
__str__
on a Form will by default render the form, it has a number of side-effects:full_clean
called on it because the__str__
includes error printing (one I've now encountered)In an ideal world, we could just change to
repr
(#725) instead offorce_text
, as this is similarly lightning fast. Instead, to err on the side of caution, I've opted for callingpprint.saferepr
instead, which is protected against recursive data structures.This has the benefit of still being faster than pformat (as far as I can tell) and avoids a certain class of problems the other options bring. But it's much slower than calling
repr
orforce_text
directly.
Marking as
WIP
because there's a number of other issues (#989, #1024, #1053, #725) are related, and one option is just to undo the changes I made to avoid too manypformat
calls. Also there's no tests ;)