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

RelationDef is not Send #892

Closed
smrtrfszm opened this issue Jul 19, 2022 · 2 comments · Fixed by #898
Closed

RelationDef is not Send #892

smrtrfszm opened this issue Jul 19, 2022 · 2 comments · Fixed by #898
Assignees

Comments

@smrtrfszm
Copy link
Contributor

Description

The type RelationDef is not Send, which broke a lot of code in multithreaded environments, because async runtimes needs Futures which implement Send.

Steps to Reproduce

Compile example code below

Expected Behavior

Should compile

Actual Behavior

It doesn't compiles, because tokio::spawn expects a Future that is Send.

Reproduces How Often

always

Versions

sea-orm: v0.9.0
database: sqlite (but it happens with all of them)
OS: Arch Linux kernel 5.18.10

Additional Information

Example code that compiles on sea-orm v0.8.0, but not on v0.9.0

Cargo.toml:

[package]
name = "send"
version = "0.1.0"
edition = "2021"

[dependencies]
sea-orm = { version = "0.9.0", features = ["sqlx-sqlite", "runtime-tokio-rustls", "macros"], default-features = false }
tokio = { version = "1.20.0", features = ["rt-multi-thread", "macros"] }

main.rs:

use sea_orm::tests_cfg::{cake, cake_filling};
use sea_orm::{Database, DbErr, EntityTrait, JoinType, QuerySelect, RelationTrait};

#[tokio::main]
async fn main() -> Result<(), DbErr> {
    let db = Database::connect("sqlite::memory:").await?;

    tokio::spawn(async move {
        let _cakes = cake::Entity::find()
            .join_rev(JoinType::InnerJoin, cake_filling::Relation::Cake.def())
            .all(&db)
            .await
            .unwrap();
    })
    .await
    .unwrap();

    Ok(())
}

Possible solution is to make the field on_condition in RelationDef Send by just adding + Send to it. It shouldn't be a big constraint in my opinion as most of the types are Send, but also it is a breaking change.

@billy1624 billy1624 self-assigned this Jul 20, 2022
@billy1624 billy1624 moved this from Triage to In Progress in SeaQL Dev Tracker Jul 20, 2022
@billy1624 billy1624 moved this to Triage in SeaQL Dev Tracker Jul 20, 2022
@billy1624
Copy link
Member

Hey @smrtrfszm, thanks for the reporting! I've opened a PR to fix this

@billy1624
Copy link
Member

This issue is caused by #793 which introduced on_conflict but without marking it as Send & Sync

@billy1624 billy1624 moved this from In Progress to Review in SeaQL Dev Tracker Jul 20, 2022
@billy1624 billy1624 moved this from Review to Done in SeaQL Dev Tracker Aug 2, 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 a pull request may close this issue.

2 participants