-
-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
column_as()
breaks PostgreSQL enum
#1920
Comments
I believe this was discussed before, but I could not find the thread. A failing testcase that pinpoints the problem is like half way to fixing the bug. I am guessing, into_model and into_json does not do the proper casting. |
That'll be appreciated! |
Facing the same issue, into_json breaks the select_as type and cast all fields as String. |
I am facing the same issue, but not via into model. I am using |
Here are some more of my findings:
file: sqlx-postgres-0.7.2/src/types/str.rs
My first impressions is based on watching how it went through the calls. It appears that sea-orm tries to build a custom macro for the Enum type. However, due to the Pg type being |
Ok, I truly do not like this hack. But for right now I am casting my enum into a "TEXT" and returning that in my query result.
My |
Hi, I've also hit this with the following: #[derive(DeriveEntityModel)]
#[sea_orm(table_name = "keys")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: KeyId,
pub owner_id: UserId,
pub schema: KeyType,
pub data: Vec<u8>,
}
#[derive(DeriveActiveEnum, EnumIter)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "keytype")]
pub enum KeyType {
#[sea_orm(string_value = "not initialized yet")]
NotInititalizedYet,
#[sea_orm(string_value = "a")]
A,
#[sea_orm(string_value = "b")]
B,
#[sea_orm(string_value = "c")]
C,
}
#[derive(FromQueryResult, DerivePartialModel)]
#[sea_orm(entity = "Entity")]
pub struct KeyMetadata {
#[sea_orm(from_col = "id")]
key_id: KeyId,
#[sea_orm(from_col = "owner_id")]
owner: UserId,
#[sea_orm(from_col = "schema")]
key_type: KeyType,
} And I'm getting the following error on postgres:
|
Description
column_as()
breaks PostgreSQL enumI am now forced to use 'role' instead of 'user_role'
Steps to Reproduce
column_as
to rename the columnExpected Behavior
Returning the role when using either into_model and into_json
Actual Behavior
into_model && column_as
into_json && column_as
(It does not show up in the json)
into_model && column
into_json && column
Reproduces How Often
Always
Workarounds
Not using column_as but using column
Reproducible Example
Don't have time to open a PR, here is my faulty query:
Working query:
Versions
├── sea-orm v0.12.3
│ ├── sea-orm-macros v0.12.3 (proc-macro)
│ │ ├── sea-bae v0.2.0 (proc-macro)
│ ├── sea-query v0.30.2
│ ├── sea-query-binder v0.5.0
│ │ ├── sea-query v0.30.2 (*)
Ubuntu 22.04.3 LTS x86_64
PostgreSQL v16
The text was updated successfully, but these errors were encountered: