SeaQL / SeaQL/sea-orm

Generate entity emits #[sea_orm(ignore)] on citext columns, excluding them from the Entity

Open
#3,168 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
9.9k
Forks
734
Avg merge
6h 36m
Merged PRs (30d)
8

Description

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

  1. 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
);
  1. Run the generate entity command
sea-orm-cli generate entity -o src/entities --database-url postgres://user:pass@localhost/demo --with-serde none
  1. 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported sea-orm-cli generate entity command against the demo and demo_pk schemas, then inspect the generated demo.rs and demo_pk.rs files. Trace the PostgreSQL citext handling in the entity generator. Done means citext fields are regular columns with select_as = "text" and save_as = "citext", and generated entities pass cargo check for both regular and primary-key columns.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rust
Domain
databases, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.