diff --git a/datasette/views/special.py b/datasette/views/special.py index 1df74f07..b28e9257 100644 --- a/datasette/views/special.py +++ b/datasette/views/special.py @@ -817,11 +817,14 @@ class ApiExplorerView(BaseView): column, ( " (primary key)" - if column in pks + if column in (pks or ["rowid"]) else "" ), ) - for column in await db.table_columns(table) + for column in ( + (["rowid"] if not pks else []) + + await db.table_columns(table) + ) } ] }, diff --git a/tests/test_api_write.py b/tests/test_api_write.py index f600d4f5..9ba08848 100644 --- a/tests/test_api_write.py +++ b/tests/test_api_write.py @@ -47,7 +47,6 @@ def _headers(token): @pytest.mark.asyncio async def test_api_explorer_upsert_example_json(ds_write): response = await ds_write.client.get("/-/api", actor={"id": "root"}) - print("STATUS", response.status_code) assert response.status_code == 200 import urllib.parse @@ -60,6 +59,26 @@ async def test_api_explorer_upsert_example_json(ds_write): assert '"age": ""' in upsert_chunk +@pytest.mark.asyncio +async def test_api_explorer_upsert_example_json_rowid_table(tmp_path_factory): + db_path = str(tmp_path_factory.mktemp("dbs") / "data.db") + conn = sqlite3.connect(db_path) + conn.execute("create table things (title text, score float)") + conn.close() + ds = Datasette([db_path]) + ds.root_enabled = True + response = await ds.client.get("/-/api", actor={"id": "root"}) + assert response.status_code == 200 + import urllib.parse + + text = urllib.parse.unquote_plus(response.text) + upsert_idx = text.index("/data/things/-/upsert") + upsert_chunk = text[upsert_idx : upsert_idx + 500] + assert '"rowid": ""' in upsert_chunk + assert '"title": ""' in upsert_chunk + assert '"score": "<score>"' in upsert_chunk + + @pytest.mark.asyncio @pytest.mark.parametrize( "content_type",