Skip to content

Raise a clear error when insert has no rows - #1451

Open
mmporong wants to merge 1 commit into
piccolo-orm:masterfrom
mmporong:fix/reject-empty-insert
Open

mmporong wants to merge 1 commit into
piccolo-orm:masterfrom
mmporong:fix/reject-empty-insert

Conversation

@mmporong

Copy link
Copy Markdown

Table.insert() can be used as a builder before calling .add(), but running it without adding any rows currently sends an invalid INSERT ... VALUES RETURNING ... statement to the database. SQLite then reports a syntax error, and other engines can return their own parser errors.

This adds an Insert._validate check, following the existing validation pattern used by update and delete queries. Running an empty insert now raises ValueError("No rows were specified to insert.") before any SQL reaches the database. Building an insert and adding rows later continues to work as before.

A regression test reproduces the empty execution path. The complete insert test module passes on SQLite with 19 tests passed and 3 skipped, and scripts/lint.sh passes.

@mmporong
mmporong force-pushed the fix/reject-empty-insert branch from 0c5fe45 to 8448799 Compare November 4, 2026 21:41
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.

1 participant