Skip to content

Commit

Permalink
Fix for ?_extra=columns bug, closes #2230
Browse files Browse the repository at this point in the history
Also refs #262 - started a test suite for extras.
  • Loading branch information
simonw committed Jan 8, 2024
1 parent 1fc76fe commit 0b2c6a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datasette/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def json_renderer(request, args, data, error, truncated=None):
elif shape in ("objects", "object", "array"):
columns = data.get("columns")
rows = data.get("rows")
if rows and columns:
if rows and columns and not isinstance(rows[0], dict):
data["rows"] = [dict(zip(columns, row)) for row in rows]
if shape == "object":
shape_error = None
Expand Down
24 changes: 24 additions & 0 deletions tests/test_table_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,3 +1362,27 @@ async def test_col_nocol_errors(ds_client, path, expected_error):
response = await ds_client.get(path)
assert response.status_code == 400
assert response.json()["error"] == expected_error


@pytest.mark.asyncio
@pytest.mark.parametrize(
"extra,expected_json",
(
(
"columns",
{
"ok": True,
"next": None,
"columns": ["id", "content", "content2"],
"rows": [{"id": "1", "content": "hey", "content2": "world"}],
"truncated": False,
},
),
),
)
async def test_table_extras(ds_client, extra, expected_json):
response = await ds_client.get(
"/fixtures/primary_key_multiple_columns.json?_extra=" + extra
)
assert response.status_code == 200
assert response.json() == expected_json

0 comments on commit 0b2c6a7

Please sign in to comment.