Skip to content

Generated columns: write-safety design #3162

Description

@tyt2y3

Follow-up to #3158 (--include-generated-columns).

Included generated columns come back as plain fields. After find, into_active_model() sets them, so the next insert/update emits them and the DB rejects ("cannot insert/update a generated column"). No mechanism enforces the help text's "must remain unset".

Two possibilities:

  • A: column lives on Model only, not ActiveModel. Compile-time guarantee: active_model.col = Set(x) won't compile. Cost: Model/ActiveModel asymmetry, so the computed value after a write must come from RETURNING (PG/SQLite) or re-SELECT (MySQL), and ActiveModel->Model reconstruction needs the field optional.
  • B: keep field on ActiveModel, mark read-only, skip in INSERT/UPDATE builder. Preserves symmetry, runtime-only guarantee (silent drop unless it errors).

A is stronger, but harder to implement.

note: the --include-generated-columns flag is currently untested

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions