Skip to content

Save grid edits against the result's statement, not the editor's current text #840

Closed

Description

@EVWorth

Severity: P1 (data safety). This is data loss in the released 1.3.0: if the editor text changes after a query runs, saving grid edits writes to whatever table and connection the editor names now, not the ones the rows came from.

What happens

Reproduction on http://localhost:1420/?mock=connected:

  1. Run SELECT * FROM products.
  2. Click Edit Mode and change the first row's name from "Mechanical keyboard" to "Renamed". Save Changes (1) lights up.
  3. Without re-running, replace the editor text with SELECT * FROM customers.
  4. Click Save Changes (1). The backend receives:
    UPDATE `customers` SET `name` = 'Renamed' WHERE `id` = 1 AND `sku` = 'SKU-1000' AND `name` = 'Mechanical keyboard' AND `price` = 249.99 AND `stock` = 143 AND `description` IS NULL LIMIT 1;
    The UPDATE targets customers using products values, and the refresh after the save runs SELECT * FROM customers.

The connection is also taken from the editor tab rather than from where the result was read. Results are shared across editor tabs today, so a Local dev result left on screen after the tab is pointed at another connection is saved to that other connection.

When the WHERE happens to match a row of the wrong table (e.g. a key-only WHERE such as id = 1), the wrong table's row is overwritten.

Cause

  • src/hooks/useGridSave.ts:60-76 builds the edit target from editorTab.content (resolveEditTarget(sql)) and the connection from editorTab.connectionId.
  • src/hooks/useGridSave.ts:166 re-runs that same editor text after saving.
  • src/components/grid/ResultsGrid.tsx:121-128 deliberately resolves the row key from activeResult.sql, because "the user keeps typing after running". The save path does not follow the same rule.

Fix

Resolve the target table from result.sql. Take the connection, database and session from useResultStore.getState().resultSource, and refresh with result.sql. Add a test that edits a cell, changes the editor text, saves, and asserts the generated statement targets the original table.

Part of #783.

Activity

  1. added
    bug
    on Oct 21, 2026
  2. added a commit that references this issue on Oct 23, 2026
    2543111
  3. added a commit that references this issue on Oct 23, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions