From 5b654fd1c87002461b7cfc329797264a0a1bda3b Mon Sep 17 00:00:00 2001 From: James Parker Date: Fri, 27 May 2016 09:22:38 +0100 Subject: [PATCH] Add support for serialising UUID type within MSSQL #961 --- redash/query_runner/mssql.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/redash/query_runner/mssql.py b/redash/query_runner/mssql.py index e8c544808..40f52a779 100644 --- a/redash/query_runner/mssql.py +++ b/redash/query_runner/mssql.py @@ -1,6 +1,7 @@ import json import logging import sys +import uuid from redash.query_runner import * from redash.utils import JSONEncoder @@ -22,6 +23,12 @@ types_map = { 5: TYPE_FLOAT, } +class MSSQLJSONEncoder(JSONEncoder): + def default(self, o): + if isinstance(o, uuid.UUID): + return str(o) + return super(MSSQLJSONEncoder, self).default(o) + class SqlServer(BaseSQLQueryRunner): @classmethod def configuration_schema(cls): @@ -123,7 +130,7 @@ class SqlServer(BaseSQLQueryRunner): rows = [dict(zip((c['name'] for c in columns), row)) for row in data] data = {'columns': columns, 'rows': rows} - json_data = json.dumps(data, cls=JSONEncoder) + json_data = json.dumps(data, cls=MSSQLJSONEncoder) error = None else: error = "No data was returned."