SeaQL / sea-orm

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

Update Strum #2088

Closed wyatt-herkamp closed 4 months ago

wyatt-herkamp commented 5 months ago

Breaking Changes

langyo commented 5 months ago

I have done some less rigorous testing on my own project, and I can currently confirm that strum 0.26 and strum 0.25 are incompatible with each other. It will affect some modules like sea_orm::DeriveRelation.

langyo commented 5 months ago

cc @tyt2y3

wyatt-herkamp commented 5 months ago

I have done some less rigorous testing on my own project, and I can currently confirm that strum 0.26 and strum 0.25 are incompatible with each other. It will affect some modules like sea_orm::DeriveRelation.

Could you please expand upon the issue?

langyo commented 5 months ago

I have done some less rigorous testing on my own project, and I can currently confirm that strum 0.26 and strum 0.25 are incompatible with each other. It will affect some modules like sea_orm::DeriveRelation.

Could you please expand upon the issue?

Here's a part of the code from my own private project:

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use strum::{Display, EnumIter, EnumString};

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

#[derive(
    Clone, Debug, PartialEq, EnumIter, EnumString, Display, DeriveActiveEnum, Deserialize, Serialize,
)]
#[serde(rename_all = "snake_case")]
#[sea_orm(rs_type = "i64", db_type = "Integer")]
pub enum Permission {
    #[sea_orm(num_value = 0)]
    Guest,
    #[sea_orm(num_value = 1)]
    User,
    #[sea_orm(num_value = 2)]
    Manager,
    #[sea_orm(num_value = 3)]
    Root,
}

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize)]
#[sea_orm(table_name = "users")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,
    #[sea_orm(default = "now()")]
    pub updated_at: DateTime<Utc>,

    #[sea_orm(indexed)]
    pub permission: Permission,

    pub name: String,
    pub password_hash: String,

    pub email: String,
    pub extra_profile: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

While using strum 0.26 instead of strum 0.25, sea_orm::DeriveEntityModel macro would crash and provide these messages:

the trait bound `models::user::PrimaryKey: Iterable` is not satisfied
the following other types implement trait `Iterable`:
  models::global_config::Column
  models::global_config::PrimaryKey
and 10 others
primary_key.rs(40, 41): required by a bound in `sea_orm::PrimaryKeyTrait`

And the Relation enum will also crashed too that provide these same messages:

the trait bound `models::user::Relation: Iterable` is not satisfied
the following other types implement trait `Iterable`:
  models::global_config::Column
  models::global_config::PrimaryKey
and 10 others
relation.rs(23, 26): required by a bound in `sea_orm::RelationTrait`

I think your patch has fixed this issue that the CI has been succeeded. I would use the new patch version of it when this PR has been merged.

wyatt-herkamp commented 5 months ago

This PR should fix it.

tyt2y3 commented 5 months ago

Thank you. I just skimmed and looks good. Would invite @billy1624 too.