Skip to content
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

Enumeration String no longer supports certain characters #1851

Closed
byeblack opened this issue Sep 9, 2023 · 7 comments · May be fixed by #2218
Closed

Enumeration String no longer supports certain characters #1851

byeblack opened this issue Sep 9, 2023 · 7 comments · May be fixed by #2218

Comments

@byeblack
Copy link

byeblack commented Sep 9, 2023

Description

Create an enumeration, an error proc-macro derive panicked message: "" occurs when inputting most non-English languages as its value.

Steps to Reproduce

  1. Add SeaORM version 0.12.0 or above to the project.
  2. Use the command sea-orm-cli generate entity -u sqlite://any.sqlite to create any entity.
  3. Add an enumeration to the created table and use a non-English language as its value.

Expected Behavior

The enumeration should be able to handle all supported characters without any errors.

Actual Behavior

An error occurs when most non-English languages are used as the enumeration value: proc-macro derive panicked message: "".

Reproduces How Often

The issue is consistently reproducible.

Workarounds

No workaround has been identified yet.

Reproducible Example

Please refer to this example link: Reproducible Example

#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(None)", enum_name = "status")]
pub enum Status {
    // #[sea_orm(string_value = "Open")]
    // #[sea_orm(string_value = "열려 있는")]

    // The following situations
    // proc-macro derive panicked message: `""` is not a valid identifier
    #[sea_orm(string_value = "打开")]
    // #[sea_orm(string_value = "開ける")]
    // #[sea_orm(string_value = "Нээлттэй")]
    // #[sea_orm(string_value = "Открыть")]
    // #[sea_orm(string_value = "يفتح")]
    Open,
    #[sea_orm(string_value = "Close")]
    Close,
}

Versions

SeaORM version: 0.12.0 and above.

@tyt2y3
Copy link
Member

tyt2y3 commented Sep 26, 2023

I am not sure, but it seems the error originate from within the derive macro, may be related to the upgrade to syn2?

@tyt2y3 tyt2y3 closed this as completed in 1abb0b2 Jan 24, 2024
@iam888
Copy link

iam888 commented Mar 26, 2024

SeaORM version 0.12.15,

proc-macro derive panicked
message: `""` is not a valid identifier

code:

//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0

use sea_orm::entity::prelude::*;

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "cate")]
pub enum Cate {
    #[sea_orm(string_value = "開ける")]
    開ける,
}

image

@ghsang
Copy link

ghsang commented May 9, 2024

@tyt2y3 Could you reopen this issue? It is still not working on 0.12.15

@tyt2y3
Copy link
Member

tyt2y3 commented May 9, 2024

can you open a PR to submit a failing test case? @ghsang

@byeblack
Copy link
Author

I've updated the examples to 0.12.15 Reproducible Example
It still has the same problem.

can you open a PR to submit a failing test case? @ghsang

@byeblack
Copy link
Author

byeblack commented May 10, 2024

Hello, @tyt2y3. I'm pretty confident I've just found the source of the error in the master branch. It's occurring in sea-orm-macros\src\derives\active_enum.rs:

...
            let enum_variant_iden = format_ident!("{}Variant", ident);
            let enum_variants: Vec<syn::Ident> = str_variants
                .iter()
                .map(|v| {
                    let v_cleaned = camel_case_with_escaped_non_uax31(v); // It turns the string into empty

                    format_ident!("{}", v_cleaned) // Error occurs here
                })
                .collect();
...

When I bypass camel_case_with_escaped_non_uax31(v), the following example can run smoothly for insertions, queries, and filtered queries. However, I'm not confident in my ability to fix it. I would greatly appreciate it if you could resolve this issue.

#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "status")]
pub enum Status {
    #[sea_orm(string_value = "Open")]
    Open,
    #[sea_orm(string_value = "열려_있는")]
    열려있는,
    #[sea_orm(string_value = "打开")]
    打开,
    #[sea_orm(string_value = "開ける")]
    開ける,
    #[sea_orm(string_value = "Нээлттэй")]
    Нээлттэй,
    #[sea_orm(string_value = "Открыть")]
    Открыть,
    #[sea_orm(string_value = "يفتح")]
    يفتح,
    #[sea_orm(string_value = "Close")]
    Close,
}

Reproducible Example

@ghsang
Copy link

ghsang commented May 10, 2024

@tyt2y3 I have opened a PR with a fix and a test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants