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

[CLI] Fix generating Enum with variant starts with number #1211

Merged
merged 1 commit into from
Nov 9, 2022

Conversation

billy1624
Copy link
Member

PR Info

Bug Fixes

  • [CLI] generate entity: add prefix _ to enum variant starts with number

@billy1624 billy1624 self-assigned this Nov 8, 2022
@billy1624 billy1624 marked this pull request as ready for review November 8, 2022 09:08
@billy1624 billy1624 requested a review from tyt2y3 November 8, 2022 09:08
@billy1624 billy1624 merged commit 1b28341 into master Nov 9, 2022
@billy1624 billy1624 deleted the fix-enum-variant-starts-with-number branch November 9, 2022 07:02
@Yuubari
Copy link

Yuubari commented Nov 9, 2022

pub enum MediaType {
    #[sea_orm(string_value = "3D")]
    _3D,

leads to a panic in the macro when trying to use the generated entity. It looks like the solution will not be that simple?

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 10, 2022

@Yuubari what's the error message?

@Yuubari
Copy link

Yuubari commented Nov 10, 2022

The same as in the original #1172:

   Compiling entity v0.1.0 (mw-tools/entity)
error: proc-macro derive panicked
 --> entity\src\sea_orm_active_enums.rs:5:49
  |
5 | #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
  |                                                 ^^^^^^^^^^^^^^^^
  |
  = help: message: `"3d"` is not a valid identifier

error: could not compile `entity` due to previous error

If I change ‘3D’ in

#[sea_orm(string_value = "3D")]

to anything else, it compiles fine.

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 10, 2022

Ah sad we need a test case for the generated Entity as well.

@billy1624
Copy link
Member Author

Oh no... we fixed one bug and another bug emerged. Now we need to fix DeriveActiveEnum.

We need test cases for generated entity. I think we can generate the entity and see if it compile.

@billy1624
Copy link
Member Author

Hey @Yuubari, please check #1219.

I'll add the tests for generated entity later. That's another PR. We need to patch it first.

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 24, 2022

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

Successfully merging this pull request may close these issues.

CLI can't generate entity if enum value starts with a number
3 participants