mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-10-24 10:17:05 +02:00
fix: replace assert with UpdateError in Table.update() method
This commit is contained in:
parent
85b1be10c8
commit
45174d556e
2 changed files with 16 additions and 2 deletions
|
|
@ -468,6 +468,10 @@ class TransactionError(Exception):
|
|||
"Operation cannot be performed while a transaction is open"
|
||||
|
||||
|
||||
class UpdateError(Exception):
|
||||
"Update did not affect exactly one row"
|
||||
|
||||
|
||||
class DescIndex(str):
|
||||
pass
|
||||
|
||||
|
|
@ -4169,8 +4173,11 @@ class Table(Queryable):
|
|||
else:
|
||||
raise
|
||||
|
||||
# TODO: Test this works (rolls back) - use better exception:
|
||||
assert rowcount == 1
|
||||
# If rowcount is not exactly 1, the row was not found or multiple rows matched:
|
||||
if rowcount != 1:
|
||||
raise UpdateError(
|
||||
f"Expected to update 1 row, but updated {rowcount}"
|
||||
)
|
||||
self.last_pk = pk_values[0] if len(pks) == 1 else pk_values
|
||||
return self
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue