You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Save grid edits against the result's statement, not the editor's current text #840
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:
Run SELECT * FROM products.
Click Edit Mode and change the first row's name from "Mechanical keyboard" to "Renamed". Save Changes (1) lights up.
Without re-running, replace the editor text with SELECT * FROM customers.
Click Save Changes (1). The backend receives:
UPDATE`customers`SET`name`='Renamed'WHERE`id`=1AND`sku`='SKU-1000'AND`name`='Mechanical keyboard'AND`price`=249.99AND`stock`=143AND`description` IS NULLLIMIT1;
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.
Activity
fix(grid): save edits against the result's source
release: 1.4.0 (#871)