Skip to content

Commit bc9c4db

Browse files
committed
.update(...) with no update argument sets last_pk
1 parent 4ab8d46 commit bc9c4db

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

sqlite_utils/db.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ def update(self, pk_values, updates=None, alter=False):
783783
pk_values = [pk_values]
784784
# Sanity check that the record exists (raises error if not):
785785
self.get(pk_values)
786+
if not updates:
787+
return self
786788
args = []
787789
sets = []
788790
wheres = []

tests/test_update.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,20 @@ def test_update_alter(fresh_db):
6464
"int_col": -10,
6565
}
6666
] == list(table.rows)
67+
68+
69+
def test_update_with_no_values_sets_last_pk(fresh_db):
70+
table = fresh_db.table("dogs", pk="id")
71+
table.insert_all([{
72+
"id": 1,
73+
"name": "Cleo",
74+
}, {
75+
"id": 2,
76+
"name": "Pancakes"
77+
}])
78+
table.update(1)
79+
assert 1 == table.last_pk
80+
table.update(2)
81+
assert 2 == table.last_pk
82+
with pytest.raises(NotFoundError):
83+
table.update(3)

0 commit comments

Comments
 (0)