Description
sea-orm-cli generate entity emits #[sea_orm(ignore, ...)] on PostgreSQL citext columns. The ignore attribute excludes the field from the generated Entity, so no matching Column variant is produced. When the citext column is the primary key, compilation fails outright; otherwise the entity compiles but the column is unusable in queries.
The generated attribute also omits save_as = "citext", which the documentation lists as required alongside select_as = "text" for this exact use case.
Steps to Reproduce
- Create the schema:
CREATE EXTENSION IF NOT EXISTS citext;
CREATE TABLE demo (
id integer PRIMARY KEY,
handle citext NOT NULL UNIQUE
);
CREATE TABLE demo_pk (
domain citext PRIMARY KEY
);
- Run the generate entity command
sea-orm-cli generate entity -o src/entities --database-url postgres://user:pass@localhost/demo --with-serde none
- Inspect the generated files and run cargo check
Expected Behavior
The citext column should be mapped as a regular column with both cast attributes, as documented in Entity Format:
#[sea_orm(column_type = "custom(\"citext\")", select_as = "text", save_as = "citext", unique)]
pub handle: String,
Per the Ignore Attribute section, ignore is meant for model attributes that map to no database column. Emitting it alongside column_type and select_as is contradictory, since those only make sense for a real column.
Actual Behavior
demo.rs (citext as a regular column):
#[sea_orm(ignore, column_type = "custom(\"citext\")", select_as = "text", unique)]
pub handle: String,
This compiles without any error, but Column::Handle does not exist, so the
column cannot be used in filter(), ActiveModel, or any query. The problem
is silent until a query returns no rows.
demo_pk.rs (citext as primary key) — note that primary_key and ignore
are emitted together:
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "demo_pk")]
pub struct Model {
#[sea_orm(
primary_key,
auto_increment = false,
ignore,
column_type = "custom(\"citext\")",
select_as = "text"
)]
pub domain: String,
}
demo_pk.rs fails to compile:
error: expected pattern, found `,`
--> src/entities/demo_pk.rs:5:39
= note: this error originates in the derive macro `sea_orm::prelude::DeriveColumn`
error: proc-macro derive produced unparsable tokens
--> src/entities/demo_pk.rs:5:39
= note: this error originates in the derive macro `DeriveEntityModel`
error: Entity must have a primary key column.
error[E0277]: the trait bound `demo_pk::PrimaryKey: PrimaryKeyToColumn` is not satisfied
error[E0004]: non-exhaustive patterns: type `&demo_pk::Column` is non-empty
error[E0004]: non-exhaustive patterns: type `&demo_pk::PrimaryKey` is non-empty
Reproduces How Often
Always, on every citext column.
Workarounds
Manually removing ignore and adding save_as = "citext" on every citext column after each generation. This makes the entity behave correctly, but has to be redone on every regeneration.
Related: #1643 and #2081 report the missing select_as / save_as on citext columns. The ignore attribute appears to be new behaviour and prevents the column from being mapped at all.
Versions
└── sea-orm v2.0.1
├── sea-orm-macros v2.0.1 (proc-macro)
│ ├── sea-bae v0.2.2 (proc-macro)
├── sea-query v1.0.1
│ └── sea-query-derive v1.0.0 (proc-macro)
sea-orm-cli 2.0.1
PostgreSQL: 18.4
OS: Fedora 44
Rust: 1.97.1
Description
sea-orm-cli generate entity emits #[sea_orm(ignore, ...)] on PostgreSQL citext columns. The ignore attribute excludes the field from the generated Entity, so no matching Column variant is produced. When the citext column is the primary key, compilation fails outright; otherwise the entity compiles but the column is unusable in queries.
The generated attribute also omits save_as = "citext", which the documentation lists as required alongside select_as = "text" for this exact use case.
Steps to Reproduce
Expected Behavior
The citext column should be mapped as a regular column with both cast attributes, as documented in Entity Format:
Per the Ignore Attribute section, ignore is meant for model attributes that map to no database column. Emitting it alongside column_type and select_as is contradictory, since those only make sense for a real column.
Actual Behavior
demo.rs(citext as a regular column):This compiles without any error, but
Column::Handledoes not exist, so thecolumn cannot be used in
filter(),ActiveModel, or any query. The problemis silent until a query returns no rows.
demo_pk.rs(citext as primary key) — note thatprimary_keyandignoreare emitted together:
demo_pk.rs fails to compile:
Reproduces How Often
Always, on every citext column.
Workarounds
Manually removing ignore and adding save_as = "citext" on every citext column after each generation. This makes the entity behave correctly, but has to be redone on every regeneration.
Related: #1643 and #2081 report the missing select_as / save_as on citext columns. The ignore attribute appears to be new behaviour and prevents the column from being mapped at all.
Versions
sea-orm-cli 2.0.1
PostgreSQL: 18.4
OS: Fedora 44
Rust: 1.97.1