Skip to content

Commit

Permalink
Fix error if array contains datetimes, closes #146
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Mar 8, 2022
1 parent ea3c2be commit 3f96cf7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django_sql_dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def displayable_rows(rows):
fixed_row = []
for cell in row:
if isinstance(cell, (dict, list)):
cell = json.dumps(cell)
cell = json.dumps(cell, default=str)
fixed_row.append(cell)
fixed.append(fixed_row)
return fixed
Expand Down
10 changes: 9 additions & 1 deletion test_project/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ def test_dashboard_sql_errors(admin_client, sql, expected_error):

@pytest.mark.parametrize(
"sql,expected_columns,expected_rows",
(("select 'abc' as one, 'bcd' as one", ["one", "one"], [["abc", "bcd"]]),),
(
("select 'abc' as one, 'bcd' as one", ["one", "one"], [["abc", "bcd"]]),
("select ARRAY[1, 2, 3]", ["array"], [["[\n 1,\n 2,\n 3\n]"]]),
(
"select ARRAY[TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02']",
["array"],
[['[\n "2004-10-19 08:23:54+00:00"\n]']],
),
),
)
def test_dashboard_sql_queries(admin_client, sql, expected_columns, expected_rows):
response = admin_client.post("/dashboard/", {"sql": sql}, follow=True)
Expand Down

0 comments on commit 3f96cf7

Please sign in to comment.