Returning model with `enum` field with `find_by_statement`
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.