Ticket #12763: django_db_debug_query_caller.diff
File django_db_debug_query_caller.diff, 1.2 KB (added by , 15 years ago) |
---|
-
django/db/backends/util.py
8 8 except ImportError: 9 9 from django.utils import _decimal as decimal # for Python 2.3 10 10 11 import traceback 12 import re 13 14 def _query_caller(dbpath_re = re.compile('.*/django/db/.*')): 15 """Returns a formatted traceback containing only the ORM invocation that initiated this query.""" 16 return traceback.format_list([t for t in traceback.extract_stack() if not dbpath_re.match(t[0])][-1:]) 17 11 18 class CursorDebugWrapper(object): 12 19 def __init__(self, cursor, db): 13 20 self.cursor = cursor … … 23 30 self.db.queries.append({ 24 31 'sql': sql, 25 32 'time': "%.3f" % (stop - start), 33 'caller': _query_caller(), 26 34 }) 27 35 28 36 def executemany(self, sql, param_list): … … 34 42 self.db.queries.append({ 35 43 'sql': '%s times: %s' % (len(param_list), sql), 36 44 'time': "%.3f" % (stop - start), 45 'caller': _query_caller(), 37 46 }) 38 47 39 48 def __getattr__(self, attr):