Skip to content

fix(grid): staged result-grid edits can hit the wrong row when a column is aliased to a primary key name #1772

Closed

Description

@ZhuchkaTriplesix

Problem

`sqlResultGridSaveEnabled` (lib/core/database/sql_table_target_extractor.dart) enables saving when every primary key name appears among the result column names. It compares names only, so `SELECT number AS id, name FROM t` counts as keyed. Editing `name` builds `UPDATE t SET name = ... WHERE id = `. If exactly one row has that `id`, the safety check (`expectDmlMatchedRows`, exactly one row) passes and a different row is changed silently.

Related: `TableMutationEngine._hasMatchingPrimaryKey` (feeds `plan.hasPrimaryKey`) uses `any` where `every` is needed for a composite key, so the preview does not warn when only part of a key is selected. The save itself is protected by the one-row check.

Fix

  • Track in the result metadata which output columns come straight from a table column of the target (not an expression or an alias of another column); enable editing and the key lookup only for those.
  • Use `every` in `_hasMatchingPrimaryKey`.
  • Tests: aliased column, expression column, composite key with one column selected.

Found in the review of the SQL safety layer.

Activity

  1. added
    bugSomething isn't working
    data-gridInteractive data grid, cell editor, filtering, groupings
    P3Low priority / Polish & Enhancements
    on Oct 25, 2026
  2. added a commit that references this issue on Oct 25, 2026
  3. ZhuchkaTriplesix commented on Oct 25, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Fixed on dev in #1803 (merged). Closing by hand: the PRs target dev, so GitHub would only close this when dev is merged into main.

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

    P3Low priority / Polish & EnhancementsbugSomething isn't workingdata-gridInteractive data grid, cell editor, filtering, groupings

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions