#5236: Provide stack trace information in sql debug entries
---------------------------------------------------+------------------------
          Reporter:  [email protected]             |         Owner:  PhiR       
  
            Status:  closed                        |     Milestone:             
  
         Component:  Database layer (models, ORM)  |       Version:  SVN        
  
        Resolution:  wontfix                       |      Keywords:  feature 
debug
             Stage:  Ready for checkin             |     Has_patch:  1          
  
        Needs_docs:  0                             |   Needs_tests:  0          
  
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by CBWhiz):

 Just in case anybody is still looking for this, create a new app and throw
 this into the _ _init_ _.py:

 {{{
 from django.conf import settings
 DEBUG_SQL_STACK = getattr(settings, 'DEBUG_SQL_STACK', False)
 if DEBUG_SQL_STACK:
     from time import time
     import traceback
     import django.db.backends.util
     class
 TracingCursorDebugWrapper(django.db.backends.util.CursorDebugWrapper):
         def trace_entry (self, sql, start):
             stop = time()
             entry = {
                 'sql': sql,
                 'time': "%.3f" % (stop - start),
                 'stack': traceback.format_stack()[:-2],
             }
             self.db.queries.append(entry)

         def execute(self, sql, params=()):
             start = time()
             try:
                 return self.cursor.execute(sql, params)
             finally:
                 sql = self.db.ops.last_executed_query(self.cursor, sql,
 params)
                 self.trace_entry(sql, start)
         def executemany(self, sql, param_list):
             start = time()
             try:
                 return self.cursor.executemany(sql, param_list)
             finally:
                 sql = '%s times: %s' % (len(param_list), sql)
                 self.trace_entry(sql, start)
     django.db.backends.util.CursorDebugWrapper = TracingCursorDebugWrapper
 }}}
 then add the app to your INSTALLED_APPS settings, and set DEBUG_SQL_STACK
 = True in your settings.py file. Works with 1.2.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/5236#comment:7>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to