SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
6.94k stars 483 forks source link

`enum`s are always lowercased in queries despire `enum_name` leading to `type does not exist` #2087

Open smndtrl opened 7 months ago

smndtrl commented 7 months ago

Description

After running the CLI to generate the types from my existing db, I got

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "ModuleType")]
pub enum ModuleType {
    #[sea_orm(string_value = "Sink")]
    Sink,
    #[sea_orm(string_value = "Source")]
    Source,
    #[sea_orm(string_value = "Transformation")]
    Transformation,
}

A simple query with it always results in a lowercase moduletype not existing - which is correct. The generator correctly extracted the type name with capitals.

Query(SqlxError(Database(PgDatabaseError { severity: Error, code: "42704", message: "type \"moduletype\" does not exist", detail: None, hint: None, position: Some(Original(65)), where: None, schema: None, table: None, column: None, data_type: None, constraint: None, file: Some("parse_type.c"), line: Some(270), routine: Some("typenameType") })))

Steps to Reproduce

  1. Have a enum with capitals in it
  2. sea-orm-cli generate entity
  3. run any insert

Expected Behavior

inserts work

Actual Behavior

Query(SqlxError(Database(PgDatabaseError { severity: Error, code: "42704", message: "type \"moduletype\" does not exist", detail: None, hint: None, position: Some(Original(65)), where: None, schema: None, table: None, column: None, data_type: None, constraint: None, file: Some("parse_type.c"), line: Some(270), routine: Some("typenameType") })))

Reproduces How Often

always

Workarounds

Reproducible Example

Versions

sea-orm v0.12.12

imwexpex commented 7 months ago

Hey! I'm facing the same issue, have you found a workaround?

tyt2y3 commented 6 months ago

I am also unsure where the lowercase is being applied. If anyone have found it, a PR would be appreciated!

ziimakc commented 6 days ago

Has the same issue in postgres, my enum name is like ModuleType in pg (I don't use sea-orm for migrations) and enum_name is set, but orm is lowercasing in on insert and so on to moduletype

I did a workaround and renamed enum in postgres to snake case module_type and same in rust enum_name, this solved an issue.

Probably in macros enum_name is parsed incorrectly or in queries it's lowercased from ModuleType into moduletype when it should be ModuleType.