Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions redash/query_runner/query_results.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import decimal
import hashlib
import logging
Expand Down Expand Up @@ -108,6 +109,8 @@ def flatten(value):
return json_dumps(value)
elif isinstance(value, decimal.Decimal):
return float(value)
elif isinstance(value, datetime.timedelta):
return str(value)
else:
return value

Expand Down
7 changes: 4 additions & 3 deletions tests/query_runner/test_query_results.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import decimal
import sqlite3
from unittest import TestCase
Expand Down Expand Up @@ -108,11 +109,11 @@ def test_creates_table_with_non_ascii_in_column_name(self):
create_table(connection, table_name, results)
connection.execute("SELECT 1 FROM query_123")

def test_creates_table_with_decimal_in_column_value(self):
def test_creates_table_with_decimal_and_timedelta_in_column_value(self):
connection = sqlite3.connect(":memory:")
results = {
"columns": [{"name": "test1"}, {"name": "test2"}],
"rows": [{"test1": 1, "test2": decimal.Decimal(2)}],
"columns": [{"name": "test1"}, {"name": "test2"}, {"name": "test3"}],
"rows": [{"test1": 1, "test2": decimal.Decimal(2), "test3": datetime.timedelta(seconds=3)}],
}
table_name = "query_123"
create_table(connection, table_name, results)
Expand Down