kopia lustrzana https://github.com/simonw/datasette
Fix for ?_extra=columns bug, closes #2230
Also refs #262 - started a test suite for extras.pull/2221/head
rodzic
1fc76fee62
commit
0b2c6a7ebd
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Ładowanie…
Reference in New Issue