Skip to content

fix: replace assert with UpdateError in Table.update() method - #867

Closed
KooshaPari wants to merge 1 commit into
simonw:mainfrom
KooshaPari:fix-9-compile-code-error
Closed

KooshaPari wants to merge 1 commit into
simonw:mainfrom
KooshaPari:fix-9-compile-code-error

Conversation

@KooshaPari

@KooshaPari KooshaPari commented Sep 13, 2026

Copy link
Copy Markdown

Bug

Table.update() used a bare assert rowcount == 1 statement to validate the update affected exactly one row. This has two problems:

  1. assert statements are stripped when Python runs in optimized mode (python -O), silently disabling the check
  2. The error message when the assert fails (AssertionError) is not informative

The code had a TODO comment acknowledging this: # TODO: Test this works (rolls back) - use better exception

Fix

  • Replaced assert rowcount == 1 with an explicit check that raises a new UpdateError exception with a descriptive message
  • Added UpdateError exception class to sqlite_utils/db.py

Testing

  • Added test_update_error_class_exists to verify the exception class works
  • All 20 tests in test_update.py pass

📚 Documentation preview 📚: https://sqlite-utils--867.org.readthedocs.build/en/867/

Copilot AI lite review requested due to automatic review settings September 13, 2026 06:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@KooshaPari KooshaPari closed this by deleting the head repository Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants