SeaQL / SeaQL/sea-orm

Returning model with `enum` field with `find_by_statement`

Open
#2,423 10 comments 3 reactions 1 assignee View on GitHub

@sinder38 is already working on this.

Since Mar 16, 2026.

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

Description

database: postgres

Enum:

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "test_status")]
pub enum TestStatus {
    #[sea_orm(string_value = "new")]
    New,
    #[sea_orm(string_value = "processing")]
    Processing,
}

Model:

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "test")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,
    pub status: Status,
    pub created_at: DateTime,
}

Query:

    let select_query = Query::select()
        .column(test::Column::Id)
        .from(test::Entity)
        .and_where(test::Column::Status.eq(TestStatus::New))
        .limit(1)
        .lock_with_behavior(LockType::Update, LockBehavior::SkipLocked)
        .to_owned();

    let update_query = Query::update()
        .table(test::Entity)
        .value(test::Column::Status, TestStatus::Processing.as_enum())
        .and_where(test::Column::Id.in_subquery(select_query))
        .returning_all()
        .to_owned();

    let stmt = db.get_database_backend().build(&update_query);

    test::Model::find_by_statement(stmt).one(db).await

Query is executed, but final result is:

Query Error: error occurred while decoding column "status": mismatched types; Rust type `core::option::Option<alloc::string::String>` (as SQL type `TEXT`) is not compatible with SQL type `test_status`

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.