Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

sqlx::raw_sql doesn't work with async-trait #3591

Open
iamsauravsharma opened this issue Nov 5, 2024 · 1 comment · May be fixed by #3613
Open

sqlx::raw_sql doesn't work with async-trait #3591

iamsauravsharma opened this issue Nov 5, 2024 · 1 comment · May be fixed by #3613
Labels

Comments

@iamsauravsharma
Copy link

Bug Description

sqlx::raw_sql query doesn't work with async-trait crate raise error

implementation of `sqlx::Executor` is not general enough
`sqlx::Executor<'_>` would have to be implemented for the type `&'0 mut sqlx::SqliteConnection`, for any lifetime `'0`...
...but `sqlx::Executor<'1>` is actually implemented for the type `&'1 mut sqlx::SqliteConnection`, for some specific lifetime `'1`

Minimal Reproduction

#[async_trait::async_trait]
trait ExecutorIssue {
    async fn check(&self, conn: &mut sqlx::SqliteConnection) {
        sqlx::raw_sql("CREATE TABLE issue-async-trait ()")
            .execute(conn)
            .await
            .unwrap();
    }
}

Info

async-trait = "0.1.83"
sqlx = { version = "0.8.2", features = ["sqlite"] }
  • Operating system: macos
  • rustc --version: rustc 1.84.0-nightly (fbab78289 2024-11-04)
@CommanderStorm
Copy link
Contributor

CommanderStorm commented Nov 28, 2024

This might not be a satisfactory solution for you, but this looks to me like an issue with how async_trait differs from the actual async trait.

Given the MRSV of sqlx, the following (removing async_trait) is a solution:

trait ExecutorIssue {
    async fn check(&self, conn: &mut sqlx::postgres::PgConnection) {
        sqlx::raw_sql("CREATE TABLE issue-async-trait ()")
            .execute(conn)
            .await
            .unwrap();
    }
}

@abonander abonander linked a pull request Nov 28, 2024 that will close this issue
1 task
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants