mirror of
https://github.com/simonw/datasette.git
synced 2026-11-23 02:19:44 +01:00
Row JSON: drop truncated, render_cell is a single object
The default row shape no longer includes "truncated", since a single row lookup cannot be truncated, and ?_extra=render_cell returns one object to match "row". With a ?_shape= both behave as they do for tables. Refs #2612 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GaqG8H8ajwxizKXdbGrtve
This commit is contained in:
parent
28184edc52
commit
cb0159e625
5 changed files with 28 additions and 19 deletions
|
|
@ -369,6 +369,7 @@ async def test_row(ds_client):
|
|||
assert data["ok"] is True
|
||||
assert data["row"] == {"id": 1, "content": "hello"}
|
||||
assert "rows" not in data
|
||||
assert "truncated" not in data
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -391,6 +392,7 @@ async def test_row_shape(ds_client, shape, expected):
|
|||
data = response.json()
|
||||
if shape in ("objects", "arrays"):
|
||||
assert "row" not in data
|
||||
assert data["truncated"] is False
|
||||
data = data["rows"]
|
||||
assert data == expected
|
||||
|
||||
|
|
@ -650,20 +652,23 @@ async def test_row_extra_render_cell():
|
|||
assert "render_cell" in data
|
||||
assert "row" in data
|
||||
|
||||
# render_cell should be a list with one row (since this is a row page)
|
||||
# render_cell is a single object to match "row"
|
||||
# Only columns modified by plugins are included (sparse output)
|
||||
render_cell = data["render_cell"]
|
||||
assert len(render_cell) == 1
|
||||
|
||||
# The row: id=1, name='Alice'
|
||||
# The 'name' column should be rendered by our plugin as <strong>Alice</strong>
|
||||
assert render_cell[0]["name"] == "<strong>Alice</strong>"
|
||||
# The 'id' column is not included since no plugin modified it
|
||||
assert "id" not in render_cell[0]
|
||||
assert data["render_cell"] == {"name": "<strong>Alice</strong>"}
|
||||
|
||||
# The regular row should still contain raw values
|
||||
assert data["row"] == {"id": 1, "name": "Alice"}
|
||||
|
||||
# With a ?_shape= render_cell is a list, matching "rows"
|
||||
response = await ds.client.get(
|
||||
"/test_row_render/test_render/1.json?_extra=render_cell&_shape=objects"
|
||||
)
|
||||
data = response.json()
|
||||
assert data["render_cell"] == [{"name": "<strong>Alice</strong>"}]
|
||||
assert data["rows"] == [{"id": 1, "name": "Alice"}]
|
||||
|
||||
finally:
|
||||
ds.pm.unregister(name="TestRenderCellPlugin")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue