[Solved]-Logging Django SQL queries with DEBUG set to False

5👍

In Django 1.3, I see class BaseDatabaseWrapper in django/db/backends/__init__.py has an attribute use_debug_cursor. This class is the wrapper for the django.db.connection object that represents the default database connection (docs). Seems like setting this attribute to true would cause Django to use a CursorDebugWrapper from django/db/backends/util.py, which logs all queries it executes, instead of a CursorWrapper, which does not.

use_debug_cursor is not present in Django 1.2, which is what I have installed on this machine at the moment, so I can’t test it right now. If I have a few minutes, I’ll try to get a dummy 1.3 project started to test this out…I may well be in over my head here!

use_debug_cursor was renamed to force_debug_cursor in Django 1.8

Leave a comment