question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DjangoIntegration conflict with MiddlewareMixin & TemplateView

See original GitHub issue

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()],
)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
untitakercommented, Aug 1, 2020

0.16.3 is out which fixes the problem.

0reactions
Jragoncommented, Feb 2, 2022

This issue was resolved for me upgrading to 1.5.4 (I had 0.15 before)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django "TemplateView" and "/media/" url conflict
is messing up media url, and files uploaded by user cannot be reached by url link, even though they are saved to folder,...
Read more >
Using mixins with class-based views - Django documentation
... and methods are likely to cause conflict between different classes and mixins. ... For example it's fine to combine TemplateView (built in...
Read more >
Django - Sentry Documentation
Sentry's Django integration reports all exceptions leading to an Internal Server Error and creates a separate scope for each request.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found