Skip to content

Wrapped types trait TryFromU64 is not implemented #2958

Description

@sinder38

Description

When using type alias for wrapped types trait TryFromU64 is not implemented

Steps to Reproduce

  1. Have a table with id you want to replace:
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveValueType)]
pub struct GroupId(i32);
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(schema_name = "public", table_name = "group")]
pub struct Model {
	#[sea_orm(primary_key)]
	pub id: GroupId,
	pub name: String,
	pub description: Option<String>,
}
  1. change i32 or other integer id type to an alias
pub type PgInt = i32;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveValueType)]
pub struct GroupId(PgInt);
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(schema_name = "public", table_name = "group")]
pub struct Model {
	#[sea_orm(primary_key)]
	pub id: GroupId,
	pub name: String,
	pub description: Option<String>,
}
3. ERROR:
```rust 
the trait bound IngredientGroupId: TryFromU64 is not satisfied
the following other types implement trait sea_orm::ActiveEnum:
AccessLevel
BatchSourceType
DataType
OperatorSign
UnitSystem
UploadStatus
VersionStatus
required for IngredientGroupId to implement TryFromU64 (rustc E0277)

Expected Behavior

A warning about unsupported types.
OR
this trait implemented the same way as in no alias case (might not be possible)

Actual Behavior

I get an error that the trait is not implemented by the derive macros.

Reproduces How Often

every time.

Workarounds

  1. just get rid of the alias all together.
  2. you could just implement it manually.
    In my specific case I define all wrapper types with macros, which also handle aliases.

Fix suggestions

I didn't read the code yet, but I assume that this trait needs knowledge of underlying type and just reading them isn't possible as macros can't read them as of date.
So this bug is likely would require 2 things:

  1. Warning for unsupported types
  2. (Optional) A feature to specify underlying type

Versions

sea-orm = { version = "2.0.0-rc.31", features = [
"with-json",
"with-uuid",
"sqlx-postgres",
"runtime-tokio-native-tls",
"macros",
] }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions