Skip to content

[P0] [bug] is_primary_key hardcoded false — UPDATE WHERE silently breaks on NULLable columns #387

Closed

Description

@EVWorth

[P0] [bug] is_primary_key hardcoded false for every column — UPDATE WHERE falls back to all columns

Context

The results grid lets users edit cell values and click Save to generate UPDATE/INSERT/DELETE statements. The WHERE clause for UPDATEs/DELETEs relies on getWhereColumns(columns) which uses is_primary_key to decide which columns to match. But the backend hardcodes is_primary_key: false in build_select_result, so the frontend sees every column as non-PK and falls back to matching against all columns — fragile against NULLable data and changes to other columns.

Problem

Per docs/audits/results.md F1.

Concrete failure: a row with email=NULL cannot match WHERE email = '[email protected]' (NULL is never = anything in SQL). MySQL returns rows_affected: 0 and the user sees "Applied 1 change(s)" with no data actually changed. The EditToolbar's "No primary key detected" warning is always shown even for tables with a real PK.

Files

  • src-tauri/crates/mas-core/src/query/executor.rs:511-516
  • src/components/grid/ResultsGrid.tsx:241-257
  • src/lib/sql-generator.ts:70-83

Repro (if applicable)

Static analysis only. Repro: run any UPDATE save against a table with a NULLable column — observe 0 rows updated despite "Applied" toast.

Expected

build_select_result populates is_primary_key correctly; getWhereColumns returns the PK; the EditToolbar doesn't show the false warning.

Proposed fix

Scope M. Read PK info from SHOW COLUMNS FROM \db`.`table`(one round-trip per result set, cached per connection) orINFORMATION_SCHEMA.COLUMNSjoined on schema/table/column. Pass throughColumnMeta.is_primary_key`.

Acceptance

A SELECT * FROM users WHERE id = 1 renders the EditToolbar WITHOUT the PK warning; handleSave produces UPDATE \users` SET `name`='x' WHERE `id`=1 LIMIT 1`.

Needs human verify

Yes

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

Activity

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

    @EVWorth
    OwnerAuthor

    Scoping note — this is not fixed by #529, despite being referenced there.

    #529 worked around it in the frontend: the grid now asks the schema inspector (api.getColumns, reading information_schema) for the real primary key and addresses rows by it, refusing the save when the key is not among the selected columns.

    The defect this issue names is still present in Rust. src-tauri/crates/mas-core/src/query/executor.rs still builds every ColumnMeta with:

    nullable: true,
    is_primary_key: false,

    MySQL does send NOT_NULL and PRIMARY_KEY in the column definition packet, but sqlx keeps ColumnFlags pub(crate), so the result-building code cannot read them. Both fields are placeholders, and the code carries a comment saying not to start trusting them.

    Remaining work is one of: get ColumnFlags exposed upstream in sqlx, decode the column-definition packet ourselves, or drop the two fields from ColumnMeta entirely so nothing can be tempted to read them. The third is the cheapest and matches how the data is actually sourced today.

    Leaving open.

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/p0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions