Skip to content

Fix count_where() raising OperationalError on nonexistent tables - #840

Closed
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix/count-where-nonexistent-table
Closed

Fix count_where() raising OperationalError on nonexistent tables#840
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix/count-where-nonexistent-table

Conversation

@ikatyal2110

@ikatyal2110 ikatyal2110 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

rows_where() and delete_where() both return gracefully when called on a table that does not yet exist, but count_where() propagates an OperationalError from SQLite instead of returning 0. This adds an existence check at the top of count_where() to make its behaviour consistent with the rest of the API. Adds a test covering count_where() and the count property on a nonexistent table.


Generated by Claude Code


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

rows_where() and delete_where() already return gracefully when called
on a table that does not exist yet; count_where() now does the same by
returning 0 instead of propagating OperationalError from SQLite.
Comment thread tests/test_introspect.py

def test_count_where_nonexistent_table(fresh_db):
assert fresh_db.table("does_not_exist").count_where() == 0
assert fresh_db.table("does_not_exist").count_where("id > ?", [5]) == 0

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This doesn't feel right to me. I prefer the existing behavior of raising an error.

@simonw

simonw commented Aug 13, 2026

Copy link
Copy Markdown
Owner

@simonw simonw closed this Aug 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.

3 participants