fix(datagrid): carry identity columns through so a new row pre-fills DEFAULT - #2589
Merged
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2588.
Root cause
PostgreSQL reports an identity column's generation in
pg_attribute.attidentityand leavescolumn_defaultnull. Measured on PostgreSQL 17:The PostgreSQL plugin reads that correctly into
PluginColumnInfo.identityKind, butPluginDriverAdapter.mapPluginColumnsnever copied the field into the app's ownColumnInfo, which had no such property. Identity died at the plugin boundary, so every downstream decision fell back to "does the column have a default", which is false for an identity column.Blast radius, measured
Wider than the report:
GENERATED BY DEFAULT AS IDENTITYfails too, withnull value in column "code" violates not-null constraint. OnlyGENERATED ALWAYSwas reported.GENERATED ALWAYSidentity cell hits the same server refusal on save.The fix
One predicate, in one place, fed by metadata that now survives the plugin boundary.
ColumnInfogainsidentityKind, andPluginDriverAdaptercarries it through.fetchAllColumnsnow routes throughmapPluginColumnsrather than its own inline copy, which had already drifted and was droppingisGenerated,generationExpressionandgenerationKind.ParsedSchemaMetadatagainscolumnIdentity, andTableRowscarries it to the two decision points.TableRows.serverAssignsValue(forColumn:)is the single answer to "does leaving this column out of an INSERT make the server supply the value". Add Row, Duplicate Row and the Set Value menu all ask it.GENERATED ALWAYS AS IDENTITYcolumn joinsgeneratedColumns, the set the app must never write. That is exactly what it is: the engine refuses both an explicit INSERT value and an UPDATE.GENERATED BY DEFAULTstays writable, because it legitimately accepts an explicit value.RowOperationsManager.addNewRowandduplicateRowread their column names and metadata from theTableRowsthey are already handed, instead of taking a second copy from the caller that could disagree.MySQL/MariaDB and SQL Server report identity in the
Extrastring rather than throughidentityKind, so both now set it:mysqlIdentityKind(extra:)beside the existingmysqlColumnIsGenerated, and.alwaysfor SQL ServerIDENTITY.Fixes found while building this, that the change is not safe without
DataChangeManager.configureForTableclearsgeneratedColumnsand only a phase-2 schema fetch refilled it, so a rerun answered from cache, a tab switch, a result-set switch or a column change left generated and identity columns writable again.generatedColumnsis now a required parameter ofconfigureForTableandrestoreStateso it cannot be forgotten, andTableRowscarries the set for the cached paths to restore from.generateInsertSQLFromStoredDatareturned nil when no column remained, andgenerateAttributedStatementsdrops a nil statement, so on a table likeCREATE TABLE t (id int GENERATED ALWAYS AS IDENTITY)the save committed its other statements, reported success, and the row vanished. It now emits the dialect's own all-defaults form:DEFAULT VALUESon PostgreSQL and SQLite (verified against PostgreSQL 17),() VALUES ()on MySQL.OVERRIDING SYSTEM VALUEandsetvalwere not dialect-gated in SQL export. Both keyed offidentityKind/isIdentityalone, so teaching SQL Server to report identity would have put PostgreSQL-only syntax into a SQL Server dump. Both are now gated on the PostgreSQL dialect.SqlDialect.from("PGlite")returned.genericalthough PGlite is PostgreSQL 17 in WASM andPGlitePluginDriversubclassesPostgreSQLPluginDriver. Beyond the export gate above, that made every statement splitter, the limit detector and the fold scanner miss$$bodies andE'…'strings on PGlite. It now maps to.postgres.Also fixed
Add Row put the cursor on column 0 unconditionally. With
GENERATED ALWAYSidentity columns now read-only, that lands on a cell the editor refuses and nothing opens, which reads as Add Row having done nothing.beginEditingFirstEditableColumnputs the caret in the first cell the row can actually take a value in.The Set Value menu offered Empty, NULL and Default on columns no statement can carry. Its selectors call
setCellValueAtColumndirectly, bypassing the edit gate, so on a generated column, a MongoDB_idor aGENERATED ALWAYSidentity the edit was staged, filtered out at statement generation, and cleared by the successful save. The menu is now gated onisColumnWritable, the same predicate the inline editor uses.Verified
build TableProtest(18 suites)build MySQLDriver / MSSQLDriver / SQLExport / PostgreSQLDriverabi mainlint TablePro Plugins TableProTestsdocsSqlDialect.fromchanged body only, so the PluginKit ABI is unchanged and no version bump is needed.The
pluginsaggregate fails locally on a pre-existing OracleNIO issue (macro expansion @TaskLocal: unknown attribute 'usableFromInlinenonisolated'), unrelated to this change, so the four plugin targets this touches were built individually. CI runs the aggregate on its own toolchain.Behaviour was measured against a live PostgreSQL 17: identity columns report a null
column_default, an explicit NULL is refused for both identity kinds, omitting the column works, andINSERT ... DEFAULT VALUESworks on an identity-only table.No UI automation: the flow needs a live PostgreSQL connection with an identity table, which the UI test harness cannot provision deterministically. SQLite, which the harness can reach, has no identity columns in this sense. The decisions are covered by unit tests instead:
TableRowsServerAssignedValueTests,TableRowsGeneratedColumnsTests, the identity and generated cases inRowOperationsManagerTests,SchemaMetadataGeneratedColumnTests,MySQLIdentityClassificationTests, and the all-defaults INSERT cases inSQLStatementGeneratorTests.The SQL export dialect gates have no unit test because
SQLExportPlugin.swiftis not in the test target's sources; they are compile-checked by the plugin build and rest onSqlDialect.from, which is tested.Reviewed by
Codex read the diff cold, twice: a defect review and an adversarial review of the approach. Six findings were acted on (the two cached-metadata P1s, the PGlite dialect regression, the ungated Set Value menu, the over-long docs bullet, and the SQL export gating). Four of its findings were verified as pre-existing rather than introduced here and are reported separately rather than folded in: the cached-rerun read of the active session registry is not bound to a result-set id, inline metadata publishes an empty set so a result is briefly writable before phase 2 lands, paste and Fill Column and the row inspector stage edits without consulting the non-writable set, and a SQL Server export writes identity values with no
SET IDENTITY_INSERT.