Documentation and test for UNIQUE constraint failed, refs #1924

pull/1930/head
Simon Willison 2022-11-30 18:05:29 -08:00
rodzic 9a1536b52a
commit 7fde34cfcb
2 zmienionych plików z 20 dodań i 1 usunięć

Wyświetl plik

@ -549,6 +549,17 @@ To return the newly inserted rows, add the ``"return": true`` key to the request
This will return the same ``"rows"`` key as the single row example above. There is a small performance penalty for using this option.
If any of your rows have a primary key that is already in use, you will get an error and none of the rows will be inserted:
.. code-block:: json
{
"ok": false,
"errors": [
"UNIQUE constraint failed: new_table.id"
]
}
.. _RowUpdateView:
Updating a row

Wyświetl plik

@ -168,7 +168,7 @@ async def test_write_rows(ds_write, return_rows):
),
(
"/data/docs/-/insert",
{"rows": [{"id": 1, "title": "Test"}]},
{"rows": [{"id": 1, "title": "Test"}, {"id": 2, "title": "Test"}]},
"duplicate_id",
400,
["UNIQUE constraint failed: docs.id"],
@ -229,6 +229,9 @@ async def test_write_row_errors(
if special_case == "invalid_json":
del kwargs["json"]
kwargs["content"] = "{bad json"
before_count = (
await ds_write.get_database("data").execute("select count(*) from docs")
).rows[0][0] == 0
response = await ds_write.client.post(
path,
**kwargs,
@ -236,6 +239,11 @@ async def test_write_row_errors(
assert response.status_code == expected_status
assert response.json()["ok"] is False
assert response.json()["errors"] == expected_errors
# Check that no rows were inserted
after_count = (
await ds_write.get_database("data").execute("select count(*) from docs")
).rows[0][0] == 0
assert before_count == after_count
@pytest.mark.asyncio