-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Migrator is not Send #954
Comments
@Palmik can you please give the full compilation error? There's nothing in |
@abonander Here's a minimal repro: async fn test() {
let pool = sqlx::PgPool::connect("foobar").await.unwrap();
let migrator = sqlx::migrate::Migrator::new(std::path::Path::new("foo"))
.await
.unwrap();
migrator.run(&pool).await.unwrap()
}
fn test_wrap() -> impl std::future::Future<Output = ()> + Send {
test()
} Error:
If you remove the But I looked into |
I'm not entirely sure that this is actually triggered by the presence of the I'm decently sure, though, that the problem is here: sqlx/sqlx-core/src/migrate/migrator.rs Lines 46 to 50 in 8e4d061
The issue is, however, that we need to specify that A semi-fix might be to change this Line 18 in 8e4d061
to be We need a label that's like "HRTB-screwiness" that we can point the Rust compiler team at and be like "figure this out, will you". cc @mehcode |
Right, I am not sure about the root cause, but without For those that stumble on this issue looking for a workaround on running migrations e.g. in their futures::executor::block_on(async {
sqlx::migrate!().run(pool).await
}) Sync it's something one would likely only run at startup, it seems like a reasonable solution. |
Based on my findings in #1015, I think I understand what's causing this. pub async fn run<'a, A>(&self, migrator: A) -> Result<(), MigrateError>
where
A: Acquire<'a>,
<A::Connection as Deref>::Target: Migrate, returns a future with lifetime pub fn run<'a, 'c, A>(&self, migrator: A) -> impl Future<Output = Result<(), MigrateError> + Send + 'a
where
A: Acquire<'c> + 'a,
<A::Connection as Deref>::Target: Migrate, |
Haven't been able to figure out how to rewrite this to make it work in the same way as |
Migrator
is not Send, so running it asynchronously from futures that need to be Send (e.g. for async_trait) is not possible.The text was updated successfully, but these errors were encountered: