Skip SQLite generated columns in generate entity#3095
Open
JMLX42 wants to merge 1 commit into
Open
Conversation
SQLite generated columns (`GENERATED ALWAYS AS (...) VIRTUAL`/`STORED`) became discoverable when SQLite discovery switched to `PRAGMA table_xinfo` (SeaQL/sea-schema#161, fixing schema-sync issue SeaQL#2995). As a side effect, `sea-orm-cli generate entity` now reverse-generates them as ordinary, writable entity fields. They are read-only at the storage layer, so they end up in the derived `ActiveModel` and any `Model::into_active_model()` round-trip fails with SQLite's "cannot INSERT/UPDATE a generated column". Drop generated columns from the discovered table before it is written to an entity. Discovery is left untouched, so schema sync keeps seeing the columns. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
PR Info
extracausessyncto add column again #2995Bug Fixes
sea-orm-cli generate entityno longer reverse-generates SQLite generated columns (GENERATED ALWAYS AS (...) VIRTUAL/STORED) as ordinary, writable entity fields.Description
SQLite generated columns became discoverable when discovery switched from
PRAGMA table_infotoPRAGMA table_xinfoin SeaQL/sea-schema#161 — a correct fix for schema sync (#2995), where generated columns were previously invisible andsynckept re-issuingALTER TABLE ... ADD COLUMN.As a side effect,
generate entityconsumes the same discovery and now emits these columns as plain fields:Because there is no marker distinguishing them, they land in the derived
ActiveModel. AnyModel::into_active_model()round-trip then includes them inINSERT/UPDATE, and SQLite rejects it:Generated columns are read-only at the storage layer, so they should not be reverse-generated as writable columns. In the Entity-First workflow they are declared with
#[sea_orm(extra = "GENERATED ALWAYS AS (...) VIRTUAL")], not produced by reverse codegen.Changes
discard_generated_columns()insea-orm-cli'sgeneratecommand. In the SQLite branch, each discovered table is passed through it beforeTableDef::write(), removing columns whoseColumnVisibilityisGeneratedVirtualorGeneratedStored.extracausessyncto add column again #2995 fix is preserved — only the reverse-codegen path drops them.test_discard_generated_columnscovering bothVIRTUALandSTOREDcolumns and confirming ordinary columns are preserved in order.This restores the pre-
rc.34generate entitybehavior for generated columns. A faithful round-trip (emitting#[sea_orm(extra = "GENERATED ...")]and marking the field read-only) would be a larger, cross-crate change —table_xinfodoes not return the generation expression — and is noted as a follow-up in #3094.Authored by an AI agent (Claude Code, Anthropic), reviewed by a maintainer of a downstream project that hit this on a routine
sea-orm-clibump.