Improved django debug

This commit is contained in:
Syrus Akbary 2015-12-04 02:34:12 -08:00
parent 14439155ee
commit bee0af1125
2 changed files with 5 additions and 8 deletions

View File

@ -42,13 +42,11 @@ class DebugSchema(Schema):
@property @property
def query(self): def query(self):
if not self._query: return self._query
return
return debug_objecttype(self._query)
@query.setter @query.setter
def query(self, value): def query(self, value):
self._query = value self._query = value and debug_objecttype(value)
def enable_instrumentation(self, wrapped_root): def enable_instrumentation(self, wrapped_root):
# This is thread-safe because database connections are thread-local. # This is thread-safe because database connections are thread-local.
@ -59,10 +57,9 @@ class DebugSchema(Schema):
for connection in connections.all(): for connection in connections.all():
unwrap_cursor(connection) unwrap_cursor(connection)
def execute(self, *args, **kwargs): def execute(self, query, root=None, *args, **kwargs):
root = kwargs.pop('root', object())
wrapped_root = WrappedRoot(root=root) wrapped_root = WrappedRoot(root=root)
self.enable_instrumentation(wrapped_root) self.enable_instrumentation(wrapped_root)
result = super(DebugSchema, self).execute(root=wrapped_root, *args, **kwargs) result = super(DebugSchema, self).execute(query, wrapped_root, *args, **kwargs)
self.disable_instrumentation() self.disable_instrumentation()
return result return result

View File

@ -100,7 +100,7 @@ class NormalCursorWrapper(object):
return method(sql, params) return method(sql, params)
finally: finally:
stop_time = time() stop_time = time()
duration = (stop_time - start_time) * 1000 duration = (stop_time - start_time)
_params = '' _params = ''
try: try:
_params = json.dumps(list(map(self._decode, params))) _params = json.dumps(list(map(self._decode, params)))