Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f96cf7

Browse files
committed
Fix error if array contains datetimes, closes #146
1 parent ea3c2be commit 3f96cf7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

django_sql_dashboard/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def displayable_rows(rows):
5252
fixed_row = []
5353
for cell in row:
5454
if isinstance(cell, (dict, list)):
55-
cell = json.dumps(cell)
55+
cell = json.dumps(cell, default=str)
5656
fixed_row.append(cell)
5757
fixed.append(fixed_row)
5858
return fixed

test_project/test_dashboard.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ def test_dashboard_sql_errors(admin_client, sql, expected_error):
127127

128128
@pytest.mark.parametrize(
129129
"sql,expected_columns,expected_rows",
130-
(("select 'abc' as one, 'bcd' as one", ["one", "one"], [["abc", "bcd"]]),),
130+
(
131+
("select 'abc' as one, 'bcd' as one", ["one", "one"], [["abc", "bcd"]]),
132+
("select ARRAY[1, 2, 3]", ["array"], [["[\n 1,\n 2,\n 3\n]"]]),
133+
(
134+
"select ARRAY[TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02']",
135+
["array"],
136+
[['[\n "2004-10-19 08:23:54+00:00"\n]']],
137+
),
138+
),
131139
)
132140
def test_dashboard_sql_queries(admin_client, sql, expected_columns, expected_rows):
133141
response = admin_client.post("/dashboard/", {"sql": sql}, follow=True)

0 commit comments

Comments
 (0)