mirror of
https://github.com/simonw/datasette.git
synced 2026-05-27 12:34:37 +02:00
Disallow null primary keys in upsert
Refs https://github.com/simonw/datasette/issues/1936#issuecomment-1341849496
This commit is contained in:
parent
a973e3ffa1
commit
4922fc2e39
2 changed files with 15 additions and 0 deletions
|
|
@ -461,6 +461,13 @@ class TableInsertView(BaseView):
|
|||
i, '", "'.join(missing_pks)
|
||||
)
|
||||
)
|
||||
null_pks = [pk for pk in pks_list if pk in row and row[pk] is None]
|
||||
if null_pks:
|
||||
errors.append(
|
||||
'Row {} has null primary key column(s): "{}"'.format(
|
||||
i, '", "'.join(null_pks)
|
||||
)
|
||||
)
|
||||
invalid_columns = set(row.keys()) - columns
|
||||
if invalid_columns and not extras.get("alter"):
|
||||
errors.append(
|
||||
|
|
|
|||
|
|
@ -299,6 +299,14 @@ async def test_insert_rows(ds_write, return_rows):
|
|||
400,
|
||||
['Row 0 is missing primary key column(s): "id"'],
|
||||
),
|
||||
# null primary key
|
||||
(
|
||||
"/data/docs/-/upsert",
|
||||
{"rows": [{"id": None, "title": "Null PK"}]},
|
||||
None,
|
||||
400,
|
||||
['Row 0 has null primary key column(s): "id"'],
|
||||
),
|
||||
# Upsert does not support ignore or replace
|
||||
(
|
||||
"/data/docs/-/upsert",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue