Skip to content

DjangoIntegration conflict with MiddlewareMixin & TemplateView #661

@cachance7

Description

@cachance7

django version: 3.0
sentry-sdk version: 0.14.3

My project has a middleware using Django's django.utils.deprecation.MiddlewareMixin. Visiting a view which subclasses django.views.generic.TemplateView while Sentry is active results in the following exception:

AttributeError: 'function' object has no attribute '__self__'
  File "django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 196, in _get_response
    middleware_method.__self__.__class__.__name__,

The following classes & url config should be sufficient to demonstrate the problem:

from django.utils.deprecation import MiddlewareMixin
from django.views.generic import TemplateView

# ...in myapp.middleware.py
class DemonstratesConflictMiddleware(MiddlewareMixin):
    def process_template_response(self, request, response):
        return response

# ...in myapp.views.py
class DemonstratesConflictView(TemplateView): 
    template_name = "index.html"


# ...in urls.py
import myapp.views
urlpatterns += [
    path('/', myapp.views.DemonstratesConflictView.as_view(), name='throws-exception'),
]

# ... in settings.py

MIDDLEWARE += ['myapp.middleware.DemonstratesConflictMiddleware']

sentry_sdk.init(
    dsn="OMITTED",
    integrations=[DjangoIntegration()],
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions