-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Intercept redirects will cause ContentNotRenderedError with django-debug-toolbar 1.9 #1009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't have the time right now to think about the best way to fix this, but maybe @jdufresne has an idea? If not I'll get back to this in the next few days. This is a regression introduced by 64ef4a3, and unfortunately there was no test to detect this :-/ |
I believe this would still be a problem for # If the response supports deferred rendering and hasn't been rendered
# yet, then ensure that it does get rendered before proceeding further.
if hasattr(response, 'render') and callable(response.render):
response.render()
# Insert the toolbar in the response.
content = force_text(response.content, encoding=response.charset) |
After further analyzing the issue, I think @hirokiky original suggested fix is the best one. I think it is incorrect for |
Thank you for your reply and fix @jdufresne and @matthiask . |
It means third party panels which returns response from process_response method should call |
I tried newest django-debug-toolbar, 1.9.
And when I enabled Intercept Redirects and accessed a view returns 302, It returned
ContentNotRenderedError
:Reason
This error caused by
content = force_text(response.content, encoding=response.charset)
, accessingresponse.content
.In this case the
response
was returned byRedirectsPanel
.https://github.com/jazzband/django-debug-toolbar/blob/master/debug_toolbar/panels/redirects.py#L9
The panel returns
SimpleTemplateResponse
object. this class will raiseContentNotRenderedError
whenresponse.content
was accessed before callingresponse.render()
.like
content = force_text(response.content, ...)
.This error wasn't on django-debug-toolbar 1.8.
And I think this change caused it
c369384
Fix idea
Simply, we can avoid this error by adding
response.render()
inRedirectsPanel
,folloing here https://github.com/jazzband/django-debug-toolbar/blob/master/debug_toolbar/panels/redirects.py#L27
like this.
Or any other nice plan? (or this issue was not correct?)
I don't know well about codes of django-debug-toolbar, so I didn't create PR yet.
Please ask and tell me anything.
The text was updated successfully, but these errors were encountered: