jazzband / django-debug-toolbar

A configurable set of panels that display various debug information about the current request/response.
https://django-debug-toolbar.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
8.08k stars 1.05k forks source link

NotImplementedError for cache clear #570

Closed Gwildor closed 10 years ago

Gwildor commented 10 years ago

I'm familiar with ticket #439, and I'm running DDT 1.0.1, which includes the fix created for that ticket. However, when I try to clear the cache with DDT enabled, I get a NotImplementedError, which originates directly from the django.core.cache.backends.base.BaseCache.clear method. As my backend, I'm running memcached. Disabling the DDT works; no exception is raised. Note that I'm trying to clear the cache from a signal receiver (not sure if that's relevant, so just throwing it out there).

When I do from django.core.cache import cache; print cache I get <CacheStatTracker for <django.core.cache.backends.memcached.MemcachedCache object at 0x106b7a290>>.

aaugustin commented 10 years ago

Can you provide the full stack trace please?

Gwildor commented 10 years ago

Here you go:

Django Version: 1.6.2
Python Version: 2.7.5
Installed Applications:
('nested_inlines',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'django.contrib.humanize',
 'ckeditor',
 'sorl.thumbnail',
 'south',
 'djcelery',
 'storages',
 'forms_builder.forms',
 'post_office',
 'feincms',
 'mptt',
 'debug_toolbar',
 'debug_toolbar_line_profiler',
 'template_timings_panel')
Installed Middleware:
(u'debug_toolbar.middleware.DebugToolbarMiddleware',
 'dogslow.WatchdogMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'pjax.middleware.PjaxMiddleware')

Traceback:
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  432.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  198.             return view(request, *args, **kwargs)
File "/Users/gwildorsok/Projects/*/src/*/admin.py" in change_view
  62.             request, object_id, form_url, extra_context=extra_context)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  29.             return bound_func(*args, **kwargs)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  25.                 return func(self, *args2, **kwargs2)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/db/transaction.py" in inner
  399.                 return func(*args, **kwargs)
File "/Users/gwildorsok/Projects/*/venv/src/django-nested-inlines/nested_inlines/admin.py" in change_view
  262.                 self.save_model(request, new_object, form, True)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/contrib/admin/options.py" in save_model
  860.         obj.save()
File "/Users/gwildorsok/Projects/*/src/*/models.py" in save
  58.         super(*, self).save(*args, **kwargs)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/db/models/base.py" in save
  545.                        force_update=force_update, update_fields=update_fields)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  582.                                    update_fields=update_fields, raw=raw, using=using)
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
  185.             response = receiver(signal=self, sender=sender, **named)
File "/Users/gwildorsok/Projects/*/src/*/signals.py" in *
  14.     cache.clear()
File "/Users/gwildorsok/Projects/*/venv/lib/python2.7/site-packages/django/core/cache/backends/base.py" in clear
  193.         raise NotImplementedError

Exception Type: NotImplementedError at /admin/*
Exception Value: 

Note that I censored some information.

And pip freeze:

Django==1.6.2
FeinCMS==1.9.3
MySQL-python==1.2.5
Pillow==2.2.2
South==0.8.4
Unidecode==0.04.14
amqp==1.4.3
anyjson==0.3.3
billiard==3.3.0.16
boto==2.23.0
celery==3.1.9
cssselect==0.9.1
decorator==3.4.0
django-celery==3.1.9
django-ckeditor-updated==4.2.8
django-debug-toolbar==1.0.1
django-debug-toolbar-line-profiler==0.4.0
django-debug-toolbar-template-timings==0.6
django-email-extras==0.2
django-forms-builder==0.10
django-mptt==0.6.0
-e git://github.com/Soaa-/django-nested-inlines.git@aaf995a223720ca7d6b4bfc74fb5707cd1bd08dd#egg=django_nested_inlines-dev
django-post-office==0.7.2
-e git://github.com/hmarr/django-ses@8a0377c40ad93f895dd7dd5f750501627f3cc78b#egg=django_ses-dev
django-storages==1.1.8
dogslow==0.9.7
feedparser==5.1.3
geopy==0.97
gunicorn==18.0
ipdb==0.8
ipython==1.1.0
jsonfield==0.9.20
kombu==3.0.12
line-profiler==1.0b3
lxml==3.3.0beta3
pyquery==1.2.8
pysolr==3.1.0
python-dateutil==2.2
python-gnupg==0.3.5
python-memcached==1.53
pytz==2013.9
raven==3.6.1
readline==6.2.4.1
redis==2.9.1
requests==2.2.0
six==1.5.2
sorl-thumbnail==11.12
sphinx-me==0.2.1
sqlparse==0.1.11
suds-jurko==0.6
wsgiref==0.1.2
xlrd==0.9.2

As you can see, it goes straight to the django.core.cache.backends.base.BaseCache.clear method, even though my backend setting is set to django.core.cache.backends.memcached.MemcachedCache. It works correctly with DDT turned off, I added a print in the clear method of the MemcachedCache class to confirm that.

aaugustin commented 10 years ago

Where does cache come from in this frame?

File "/Users/gwildorsok/Projects/*/src/*/signals.py" in *
  14.     cache.clear()
Gwildor commented 10 years ago

From from django.core.cache import cache

aaugustin commented 10 years ago

That's weird. I don't know how this could happen. Try inserting some debugging statements in debug_toolbar.panels.cache.CachePanel.enable/disable_instrumentation?

Gwildor commented 10 years ago

Really weird. I've set up a basic test project in an attempt to reproduce this problem in an isolated project, but I'm not able to. Tried different things, but everything up to clearing cache from inside a signal seems to work. When printing cache inside the signal I don't get CacheStatTracker either, just Django's MemcachedCache.

Being that I can't reproduce it, I'm closing this issue.

chrkr commented 9 years ago

It took me all of 10 minutes to find out why this was happening in my project, inside a view function:

You won't find this occurring outside a view function, because on the way back out, the processing passes through the debug toolbar middleware again, this time calling disable_instrumentation on the cache panel, which replaces the cache/get_cache with the original values again.