Skip to content

fix(grid): clear primary key columns when duplicating a row in staging buffer #888

Description

@ZhuchkaTriplesix

Summary

In VirtualResultGrid._handleDuplicateRow:

void _handleDuplicateRow(int row) {
  if (widget.stagingBuffer == null || row >= _sortedRows.length) return;
  final rowData = _sortedRows[row];
  widget.stagingBuffer!.addRow(List<String>.from(rowData));
}

When a user triggers "Duplicate Row" (via row context menu or keyboard shortcut), the row is cloned verbatim into the staging buffer, including the primary key value (e.g. id = 42).

When the user clicks Save, TableMutationEngine constructs an INSERT query containing the duplicate primary key:
INSERT INTO users (id, name, email) VALUES (42, 'Alice', ...);
This causes an immediate database error (duplicate key value violates unique constraint / PRIMARY KEY must be unique), failing the save operation.

Repro

  1. Open Table Browser on a table with a primary key.
  2. Right-click any row and select "Duplicate Row".
  3. A new row appears at the bottom with all identical values, including the PK.
  4. Click Save.
  5. Save fails with a unique constraint violation error.

Scope

• When duplicating a row, identify primary key columns (using primaryKeys / columnMeta).
• Reset primary key cell values to empty string or default sentinel so the database can generate a fresh unique key.
• Alternatively, provide a duplicateRow(int index, {Set<String> primaryKeys}) helper on DataGridStagingBuffer that blanks PK columns automatically.
• Add tests in test/features/workspace/data_grid_staging_buffer_test.dart.

Out of scope

• Natural composite keys where the user is required to manually input distinct key components (the user can still edit the blank cell before saving).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingdata-gridInteractive data grid, cell editor, filtering, groupingsfrontendTheme parser epic label: frontenduxUser experience, keyboard shortcuts and interactions

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions