diff options
| author | Rob Hudson | 2008-09-23 21:06:39 -0700 |
|---|---|---|
| committer | Rob Hudson | 2008-09-23 21:06:39 -0700 |
| commit | 159e690ff3d07c8821332942ae722bdf0bdf5208 (patch) | |
| tree | e0c2284be0ae9fb840abdae142db18bb03ce849b | |
| parent | 7ea7e780b775680be3050a8d6eb71f63b5a1fd34 (diff) | |
| download | django-debug-toolbar-159e690ff3d07c8821332942ae722bdf0bdf5208.tar.bz2 | |
Add catch for non JSON serializable objects and don't show the EXPLAIN link for
these.
| -rw-r--r-- | debug_toolbar/panels/sql.py | 7 | ||||
| -rw-r--r-- | debug_toolbar/templates/debug_toolbar/panels/sql.html | 6 |
2 files changed, 11 insertions, 2 deletions
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index e4e3c02..9223cb7 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -16,12 +16,17 @@ class DatabaseStatTracker(util.CursorDebugWrapper): return self.cursor.execute(sql, params) finally: stop = time.time() + _params = None + try: + _params = simplejson.dumps(params) + except TypeError: + pass # object not JSON serializable # We keep `sql` to maintain backwards compatibility self.db.queries.append({ 'sql': self.db.ops.last_executed_query(self.cursor, sql, params), 'time': stop - start, 'raw_sql': sql, - 'params': simplejson.dumps(params), + 'params': _params }) util.CursorDebugWrapper = DatabaseStatTracker diff --git a/debug_toolbar/templates/debug_toolbar/panels/sql.html b/debug_toolbar/templates/debug_toolbar/panels/sql.html index 0a8a6e0..052b36a 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/sql.html +++ b/debug_toolbar/templates/debug_toolbar/panels/sql.html @@ -11,7 +11,11 @@ {% for query in queries %} <tr class="{% cycle 'row1' 'row2' %}"> <td>{{ query.time|floatformat:"4" }}</td> - <td><a class="remoteCall" href="/__debug__/sql_explain/?sql={{ query.raw_sql|urlencode }}¶ms={{ query.params|urlencode }}&time={{ query.time|floatformat:"4"|urlencode }}">EXPLAIN</a></td> + <td> + {% if query.params %} + <a class="remoteCall" href="/__debug__/sql_explain/?sql={{ query.raw_sql|urlencode }}¶ms={{ query.params|urlencode }}&time={{ query.time|floatformat:"4"|urlencode }}">EXPLAIN</a> + {% endif %} + </td> <td class="syntax">{{ query.sql|safe }}</td> </tr> {% endfor %} |
