Open andrey-oparin opened 8 years ago
Hi, i upgrade django-debug-toolbar to 1.4, and i get bug with display SQL
I see the same issue, also with django-debug-toolbar 1.4. @andrey-oparin - did you find any way to fix this?
same for ddt-1.4 and django 1.9.6
similar in ddt-1.6 and django 1.10.2
I also have this issue with 1.6 and 1.10. Are the developers still around for this project? I've been looking through these GitHub issues and I don't think I've seen a single comment from them?
Fix here https://github.com/faulkner/django-debug-panel/commit/a8bc8a28d1b9def22632cbdb40a488ce27654f0b , works with Django 1.10.1 and django-debug-toolbar 1.6
Works perfectly, thank you!
The fix that @chuckus provides doesn't seem to work with AJAX requests (all AJAX requests will show a "No SQL queries" error when viewed through the Chrome extension).
As @jgbishop pointed out, the faulkner patch only fixes the direct requests and the AJAX requests in the panel no longer work. Here's a patch that worked for me:
replace: if hasattr(panel, 'generate_stats'):
with: if hasattr(panel, 'generate_stats') and not panel.get_stats():
Essentially, only generate the stats if they haven't been generated already. This seems to prevent the double escaping and probably is more efficient, too.
Since this project seems to be dead, you can use this patch by inheriting and overriding the one method that has the issue and then using it in MIDDLEWARE_CLASSES
instead. Here's a patched middleware to use:
"""
This is to patch django-debug-panel to work with latest versions of
django-debug-toolbar. The issue is SQL is double-escaped so this
version only calls `generate_stats` on panels if they haven't
already been called.
"""
import threading
import time
import debug_panel
from django.core.urlresolvers import reverse
from debug_panel.cache import cache
from debug_panel.middleware import DebugPanelMiddleware
class DebugPanelMiddlewareFixed(DebugPanelMiddleware):
def process_response(self, request, response):
"""
Store the DebugToolbarMiddleware rendered toolbar into a cache store.
The data stored in the cache are then reachable from an URL that is appened
to the HTTP response header under the 'X-debug-data-url' key.
"""
toolbar = self.__class__.debug_toolbars.get(threading.current_thread().ident, None)
response = super(DebugPanelMiddleware, self).process_response(request, response)
if toolbar:
# for django-debug-toolbar >= 1.4
for panel in reversed(toolbar.enabled_panels):
if hasattr(panel, 'generate_stats') and not panel.get_stats(): # PATCH HERE
panel.generate_stats(request, response)
cache_key = "%f" % time.time()
cache.set(cache_key, toolbar.render_toolbar())
response['X-debug-data-url'] = request.build_absolute_uri(
reverse('debug_data', urlconf=debug_panel.urls, kwargs={'cache_key': cache_key}))
return response