Skip to content

Don't run context processors for redirect template. #565

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

Closed
wants to merge 1 commit into from

Conversation

living180
Copy link
Contributor

In certain configurations, applying the context processors when rendering the redirect template can cause exceptions. For example, assume the folllowing Django settings:

APPEND_SLASH = True

MIDDLEWARE_CLASSES = (
    'debug_panel.middleware.DebugPanelMiddleware',
    'django.middleware.common.CommonMiddleware',
    ...
    'custom.middleware.CustomMiddleware'
)

TEMPLATE_CONTEXT_PROCESSORS = (
    ...
    'custom.context_processors.custom',
    ....
)

Further, assume that custom.middleware.CustomMiddleware sets an attribute on the request that custom.context_processors.custom tries to access. If django.middleware.common.CommonMiddleware causes a redirect, (e.g. as a result of the APPEND_SLASH setting), the attribute that custom.context_processors.custom needs will never get set on the request. Then when initializing the RequestContext in order to render debug_toolbar/redirect.html,an exception will occur when custom.context_processors.custom tries to access the missing attribute.

Since no context processors are needed to render the debug_toolbar/redirect.html template, avoid this problem by replacing render with render_to_response, which does not apply context processors to the template context.

@aaugustin
Copy link
Contributor

Ah, I changed this recently because I couldn't figure out why the DDT used render_to_response instead of the more common render. This needs a test. Other views may have the same problem.

@catalanojuan
Copy link
Contributor

This can be closed now since I added the same fix with the missing test in the PR shown above.

@aaugustin
Copy link
Contributor

No, it cannot. There are other instances of render() that may trigger the same issue.

@catalanojuan
Copy link
Contributor

@aaugustin thanks for your answer! I thought that this PR referred only to the instance in the redirects panel, but I get it that it might be better to also fix the other ones, should I extend the patch in the other PR to fix the other instances?

@jezdez jezdez closed this Apr 15, 2014
@jezdez jezdez reopened this Apr 15, 2014
@aaugustin
Copy link
Contributor

Do as you wish!

@aaugustin aaugustin closed this in 0fabf93 Apr 19, 2014
ryneeverett pushed a commit to ryneeverett/django-debug-toolbar that referenced this pull request Oct 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants