django-debug-toolbar: After upgrading to Django 4.2 LTS, I receive AttributeError on each page load. Using DDT 4.0.0

E0506 14:25:32.246 django.request:241 Internal Server Error: /dashboard/
Traceback (most recent call last):
  File "C:\Users\Owner\.virtualenvs\premind-6P0nJig8\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\Owner\.virtualenvs\premind-6P0nJig8\lib\site-packages\sentry_sdk\integrations\django\middleware.py", line 176, in __call__
    return f(*args, **kwargs)
  File "C:\Users\Owner\.virtualenvs\premind-6P0nJig8\lib\site-packages\debug_toolbar\middleware.py", line 64, in __call__
    panel.disable_instrumentation()
  File "C:\Users\Owner\.virtualenvs\premind-6P0nJig8\lib\site-packages\debug_toolbar\panels\cache.py", line 217, in disable_instrumentation
    self._unmonkey_patch_cache(cache)
  File "C:\Users\Owner\.virtualenvs\premind-6P0nJig8\lib\site-packages\debug_toolbar\panels\cache.py", line 171, in _unmonkey_patch_cache
    if original_method.__func__ == getattr(cache.__class__, name):
AttributeError: 'function' object has no attribute '__func__'

Commenting debug_toolbar.panels.cache.CachePanel allows DDT to continue to work.

# settings.py
MIDDLEWARE = [
    "django.middleware.gzip.GZipMiddleware",
]

if DEBUG_TOOLBAR:
    INSTALLED_APPS += ["debug_toolbar"]
    MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]
    DEBUG_TOOLBAR_PANELS = [
        "debug_toolbar.panels.history.HistoryPanel",
        "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.staticfiles.StaticFilesPanel',  # breaks if minio is enabled
        "debug_toolbar.panels.templates.TemplatesPanel",
        # "debug_toolbar.panels.cache.CachePanel",  # commenting this line allows DDT to continue to work
        "debug_toolbar.panels.signals.SignalsPanel",
        "debug_toolbar.panels.logging.LoggingPanel",
        "debug_toolbar.panels.redirects.RedirectsPanel",
        "debug_toolbar.panels.profiling.ProfilingPanel",
    ]

Please let me know if you need any more information in order to solve this issue

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 23 (16 by maintainers)

Most upvoted comments

I’m also seeing this after upgrading from django 4.1 to 4.2:

Environment:


Request Method: GET
Request URL: https://www.ideasenfoto.localhost:8000/admin/

Django Version: 4.2.1
Python Version: 3.11.2
Installed Applications:
['idf.core',
 'django.contrib.auth',
 'idf.auth',
 'idf.backoffice',
 'idf.admin',
 'idf.shipping',
 'idf.reports',
 'nested_admin',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.contenttypes',
 'polymorphic',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'django.contrib.gis',
 'ckeditor',
 'idf.coupons',
 'storages',
 'debug_toolbar',
 'django_afip',
 'django.contrib.postgres',
 'django_inlinecss',
 'rest_framework',
 'idf.sync',
 'idf.imaging',
 'idf.api',
 'idf.tenants',
 'manifest',
 'mptt',
 'payments',
 'anymail',
 'idf.emails']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/sentry_sdk/integrations/django/middleware.py", line 176, in __call__
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/debug_toolbar/middleware.py", line 64, in __call__
    panel.disable_instrumentation()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/debug_toolbar/panels/cache.py", line 217, in disable_instrumentation
    self._unmonkey_patch_cache(cache)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/debug_toolbar/panels/cache.py", line 171, in _unmonkey_patch_cache
    if original_method.__func__ == getattr(cache.__class__, name):
       ^^^^^^^^^^^^^^^^^^^^^^^^

Exception Type: AttributeError at /admin/
Exception Value: 'function' object has no attribute '__func__'

I see sentry in the stacktrace there. AFAIK, sentry does some money-patching too, so there might be a conflict there.

My settings.py includes:

init_sentry(
    attach_stacktrace=True,
    before_send=before_send,
    integrations=[
        AwsLambdaIntegration(timeout_warning=True),
        CeleryIntegration(),
        DjangoIntegration(),
        LoggingIntegration(event_level=logging.WARNING),
    ],
    release=version,
    in_app_exclude=["logging"],
    ignore_errors=["idf.core.views.TestException"],
    traces_sample_rate=0,
    environment=TENANT_SLUG,
)

If I comment out this block, my site works again. It seems that the conflict arises when debug toolbar AND sentry are both present.