Skip to content

fix(grid): identify rows by the real key, before the edit not after (#387, #400) - #626

Merged
EVWorth merged 2 commits into
mainfrom
fix/results-primary-key
Sep 11, 2026
Merged

EVWorth merged 2 commits into
mainfrom
fix/results-primary-key

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 11, 2026

Copy link
Copy Markdown
Owner

What

is_primary_key is false on every result column and always will be — sqlx keeps MySQL's ColumnFlags pub(crate), so the executor has nothing to populate it from. getWhereColumns read that metadata, found no key, and fell back to matching on every column — for every table, key or no key.

Row identity now comes from the schema, in a new useRowKey hook, resolved when the result arrives rather than when Save is pressed. A warning that appears only after a failed save came too late; the toolbar now says what is wrong while there is still time to change the query.

Beyond restoring the key:

  • UNIQUE-index fallback. No primary key → the narrowest UNIQUE index over NOT NULL columns. Nullable columns are excluded on purpose: UNIQUE does not constrain NULLs, and both MySQL 8.0.46 and MariaDB 11 accept two rows holding NULL there (verified live).
  • "No key" and "you didn't select the key" are different problems. The second names the columns to add.
  • A failed schema read is unknown, not no key. Claiming no key is what invites the all-columns WHERE this exists to avoid.

getWhereColumns and getPrimaryKeyColumns are removed rather than fixed — both read metadata that cannot answer the question.

Also: a crash in the code this now depends on

A functional index (UNIQUE KEY ((LOWER(a)))) leaves COLUMN_NAME NULL in INFORMATION_SCHEMA.STATISTICS. get_indexes decoded it as String and panicked, failing the index read for the whole table. EXPRESSION cannot be selected instead — MariaDB has no such column and errors on the query. The index is now listed with no columns, and callers needing identifying columns skip it naturally.

Verification

  • 2253 unit + 297 browser tests pass
  • New useRowKey tests: 10, including mutation-checked (removing the nullable filter fails the right one)
  • New live-server Rust regression test; it panics against the old code
  • Duplicate-NULLs-under-UNIQUE confirmed on MySQL 8.0.46 and MariaDB 11

Closes #387
Closes #400

🤖 Generated with Claude Code

EVWorth and others added 2 commits September 10, 2026 19:37
A functional index — `UNIQUE KEY ((LOWER(a)))` — leaves COLUMN_NAME NULL in
INFORMATION_SCHEMA.STATISTICS, with the expression in a separate column.
`get_indexes` decoded that as `String`, so reading indexes for any table
carrying one panicked with UnexpectedNullError and took down the schema read
for the entire table, not just that row.

EXPRESSION cannot be selected in its place: MariaDB has no such column and
errors on the query (verified on 11.x). The index is now listed with no
columns, which is the honest answer for something indexing an expression
rather than a column, and callers that need identifying columns — the grid,
resolving how to address a row — skip it naturally.

Covered by a live-server regression test; it panics against the old code.

Co-Authored-By: Claude Opus 5 <[email protected]>
Result-set metadata reports `is_primary_key` as false for every column, and
always will: sqlx keeps MySQL's ColumnFlags `pub(crate)`, so the executor has
nothing to populate it from. `getWhereColumns` read that metadata, found no
key, and fell back to matching on every column — for every table, whether or
not it had a key (#387, #400).

Row identity now comes from the schema, in `useRowKey`, resolved when the
result arrives rather than when Save is pressed. A warning that appears only
after a failed save is a warning that came too late; the toolbar now says
what is wrong while there is still time to change the query.

Three things it does that the old check did not:

- Falls back to a UNIQUE index over NOT NULL columns when there is no primary
  key, narrowest first. Nullable columns are excluded on purpose: UNIQUE does
  not constrain NULLs, and both MySQL 8 and MariaDB 11 accept two rows holding
  NULL there — verified.
- Distinguishes "this table has no key" from "your query did not select it",
  which call for different responses from the user, and names the columns to
  add.
- Treats a failed schema read as unknown rather than as no-key. Claiming there
  is no key is what invites the all-columns WHERE this exists to avoid.

`getWhereColumns` and `getPrimaryKeyColumns` are removed rather than fixed —
both read the metadata that cannot answer the question.

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth merged commit 4fee7e9 into main Sep 11, 2026
12 checks passed
@EVWorth
EVWorth deleted the fix/results-primary-key branch September 11, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant