fix(sql): error on unknown columns in single-table scope (SQLR-2)#166
Merged
Conversation
SingleTableScope::lookup silently returned Value::Null for any column not in the schema (legacy eval_expr behavior), while JoinedScope errors. Net effect: a typo'd column in WHERE silently matched every row — and on UPDATE/DELETE, mutated or deleted the entire table. Tighten SingleTableScope::lookup to error on unknown columns, matching JoinedScope. Schema columns whose cells were never written still read as NULL (omitted-from-INSERT semantics unchanged). Audit found no existing test pinning the lenient behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SingleTableScope::lookupsilently returnedValue::Nullfor any column not in the schema (legacyeval_exprbehavior), whileJoinedScopeerrors. The ticket framed this as a SELECT-projection cliff, but the projection list was already validated separately — the real surface was expression evaluation:SELECT id FROM t WHERE typo IS NULLsilently matched every rowUPDATE/DELETEmeant a typo'd WHERE mutated or deleted the entire tableORDER BY typosilently no-op'dFix
SingleTableScope::lookupnow checkscontains_columnand errors with the sameColumn '…' does not exist on table '…'message the projection validator uses, matchingJoinedScope. A schema column whose cell was never written (omitted from the INSERT column list) still reads as NULL —where_is_null_works_on_omitted_columnpins that and still passes.GroupRowScope(HAVING) already errored; no change.Audit
All 670 pre-existing engine tests pass unmodified — nothing pinned the lenient behavior.
Tests
Four new regression tests (verified to fail with the fix reverted):
where_unknown_column_errors_single_tableorder_by_unknown_column_errors_single_tableupdate_with_unknown_column_in_where_errors_and_mutates_nothingdelete_with_unknown_column_in_where_errors_and_deletes_nothingFull CI matrix green locally (build / test / clippy / doc / fmt with the standard excludes). On-disk REPL smoke: typo'd WHERE statements error cleanly, data intact across reopen.
Docs
Added the WHERE-typo and DELETE-typo cases to
docs/smoke-test.md§1.10.Follow-up
Single-table scope still ignores table qualifiers (
SELECT x.id FROM tworks) — filed as SQLR issue #14 (qualifier validation needs alias plumbing through everyeval_exprcallsite).Refs: SQLR-2, PR #99 (SQLR-5), code review concern #3.
🤖 Generated with Claude Code