Skip to content

[P1] [bug] getWhereColumns uses all columns in WHERE — fragile against NULL (compounds F1) #400

Closed

Description

@EVWorth

[P1] [bug] getWhereColumns uses ALL columns in WHERE when no PK — fragile against NULL/sparse columns (compounded with F1)

Context

When is_primary_key is unavailable, getWhereColumns falls back to using every column in the WHERE clause. Compounded with F1 (PK always false), this is the default path.

Problem

Per docs/audits/results.md F7.

WHERE clause becomes WHERE id=1 AND name='old' AND email=NULL AND .... Two failure modes: (a) if any column is NULL, the WHERE clause is unsatisfiable for that row — MySQL returns 0 rows updated; (b) if a column value was changed NULL→X, the original-NULL comparison fails. Save handler shows "Applied N change(s)" but nothing changed. No error to the user.

Files

  • src/lib/sql-generator.ts:70-83
  • src/lib/sql-generator.ts:14-19 (buildWhereClause)

Repro (if applicable)

Static analysis only.

Expected

Until F1 lands: refuse to generate UPDATE/DELETE if hasPrimaryKey === false — show blocking dialog "Cannot generate UPDATE/DELETE without a primary key". After F1: PK is always correct, this fallback never triggers.

Proposed fix

Scope M. (a) primary fix is F1. (b) Until F1 lands, add a blocking dialog in handleSave for the no-PK case. (c) Unit test for getWhereColumns with mixed NULL/non-NULL.

Acceptance

Editing a NULLable column on a table without PK shows the blocking dialog; user can apply via copy-as-UPDATE or cancel.

Needs human verify

Yes

Labels: audit, area/results, severity/p1, kind/bug

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/results
    on Jul 31, 2026
  2. EVWorth commented on Sep 4, 2026

    @EVWorth
    OwnerAuthor

    Partial — recording what #529 verified, since the premise has drifted.

    The issue says getWhereClause uses all columns and is fragile against NULL. Two halves:

    • NULL handling is already correct. buildWhereClause emits IS NULL rather than = NULL. That part of the report is stale.
    • All-columns matching is gone for the normal path: fix(grid): write edits to the right table, addressed by the real key #529 addresses rows by the real primary key from information_schema, and refuses the save outright when the key is not among the selected columns.

    What remains: float and blob columns still compare badly in any fallback WHERE. That is now mitigated rather than fixed — the rows-affected check added in #529 will report a mismatch instead of silently claiming success.

    Leaving open for the float/blob comparison, with the NULL half struck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/resultsauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions