Skip to content

profiling panel causes custom middleware to skip "process_exception" call #1135

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
ptink opened this issue Jan 24, 2019 · 2 comments
Closed

Comments

@ptink
Copy link

ptink commented Jan 24, 2019

I detailed my experiments with this here: https://stackoverflow.com/questions/54346767/django-2-0-custom-middleware-process-exception-hook-not-firing?noredirect=1#comment95511527_54346767

Basically I have a custom middleware class that has a process_exception method, but if I also have debug toolbar enabled with the profiling panel added in DEBUG_TOOLBAR_PANELS than the process_exception method in my middleware class will never fire, I can see the traceback for the error occuring but the returned response is a standard django 500 debug page.

Middleware:

class MyMiddleware(MiddlewareMixin):
    def process_exception(self, request, exception):
        print("Exception!")

Activated middleware

DJANGO_MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'path.to.MyMiddleware',
]

Panels:

DEBUG_TOOLBAR_PANELS = (
    'debug_toolbar.panels.versions.VersionsPanel',
    'debug_toolbar.panels.timer.TimerPanel',
    'debug_toolbar.panels.settings.SettingsPanel',
    'debug_toolbar.panels.headers.HeadersPanel',
    'debug_toolbar.panels.request.RequestPanel',
    'debug_toolbar.panels.sql.SQLPanel',
    'debug_toolbar.panels.templates.TemplatesPanel',
    'debug_toolbar.panels.cache.CachePanel',
    'debug_toolbar.panels.signals.SignalsPanel',
    'debug_toolbar.panels.logging.LoggingPanel',
    'debug_toolbar.panels.redirects.RedirectsPanel',
    'debug_toolbar.panels.profiling.ProfilingPanel',  # commenting this out works
)
@ptink
Copy link
Author

ptink commented Jan 24, 2019

This duplicates #497 I've just noticed. It would be nice if there was some sort of warning raised because this broke for me in an extremely non-obvious way

@matthiask
Copy link
Member

#1132 will make this worse... I wonder what the best way to fix this might be.

It seems to me that this just surfaces the brokenness of the old way of writing Django middleware (process_view / process_response / process_exception)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants