Skip to content
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

DjangoIntegration conflict with MiddlewareMixin & TemplateView #661

Closed
cachance7 opened this issue Mar 30, 2020 · 11 comments · Fixed by #773
Closed

DjangoIntegration conflict with MiddlewareMixin & TemplateView #661

cachance7 opened this issue Mar 30, 2020 · 11 comments · Fixed by #773
Labels
Type: Bug Something isn't working

Comments

@cachance7
Copy link

cachance7 commented Mar 30, 2020

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

@untitaker untitaker added the Type: Bug Something isn't working label Apr 8, 2020
@untitaker
Copy link
Member

Sorry for the slow response, I will look into this now

@untitaker
Copy link
Member

untitaker commented Apr 8, 2020

Sorry, can't reproduce. Can you provide a template that exhibits this issue?

@untitaker
Copy link
Member

Closing due to lack of activity, please respond so we can continue investigating

@kmmbvnr
Copy link

kmmbvnr commented Jul 31, 2020

@untitaker I've got the same error. With custom middleware with process_template_response and sentry enabled

@untitaker
Copy link
Member

untitaker commented Jul 31, 2020 via email

@kmmbvnr
Copy link

kmmbvnr commented Jul 31, 2020

Here is the simple gist. I've added only new style custom middleware with process_template_response method

git clone https://gist.github.com/8760daf908e58a600af4b5ad623fd3e5.git sentry-bug
cd sentry-bug
poetry install
poetry run python ./manage.py runserver

Access to http://127.0.0.1:8000/

Django version 3.1rc1, using settings 'settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Internal Server Error: /login/
Traceback (most recent call last):
  File "/tmp/sentry-bug/.venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/tmp/sentry-bug/.venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 198, in _get_response
    middleware_method.__self__.__class__.__name__,
AttributeError: 'function' object has no attribute '__self__'

Without sentry.init in settings.py the sample works correctly and shows login page

@untitaker
Copy link
Member

excellent, thank you

@untitaker
Copy link
Member

yes, so the crucial information missing from op was that this can only be reproduced using 3.1, which is not what you get with pip install django. I've posted a PR. Why do people use pre-release versions?

@untitaker
Copy link
Member

0.16.3 is out which fixes the problem.

@memclutter
Copy link

Not fixed in 0.16.2

@Jragon
Copy link

Jragon commented Feb 2, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants