diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index b842afe..bbc6177 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -783,6 +783,8 @@ class Table: pk_values = [pk_values] # Sanity check that the record exists (raises error if not): self.get(pk_values) + if not updates: + return self args = [] sets = [] wheres = [] diff --git a/tests/test_update.py b/tests/test_update.py index 2d46ffe..060ef32 100644 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -64,3 +64,20 @@ def test_update_alter(fresh_db): "int_col": -10, } ] == list(table.rows) + + +def test_update_with_no_values_sets_last_pk(fresh_db): + table = fresh_db.table("dogs", pk="id") + table.insert_all([{ + "id": 1, + "name": "Cleo", + }, { + "id": 2, + "name": "Pancakes" + }]) + table.update(1) + assert 1 == table.last_pk + table.update(2) + assert 2 == table.last_pk + with pytest.raises(NotFoundError): + table.update(3)