-
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
fix: hide sqlx_postgres::any
#3254
Conversation
Nesting of transactions is intentional. Once inside a transaction, Something else is going on here. |
@abonander I see. I can take another look and try to debug it + fix it. I assume the nested transactions does not get committed but rollbacked. Let me take a look again |
Okay, I found the issue: use sqlx::{postgres::{PgConnectOptions, PgPoolOptions}, ConnectOptions, PgPool, Postgres, Row, Transaction};
// Comment out `use sqlx::Acquire` and comment in `sqlx::postgres::any::AnyConnectionBackend`
// and the transaction will not be committed.
//
// use sqlx::postgres::any::AnyConnectionBackend;
use sqlx::Acquire;
#[tokio::main]
async fn main() {
let url = "postgres://dario@localhost/sqlx".parse().unwrap();
let opts: PgConnectOptions = ConnectOptions::from_url(&url).unwrap();
let pool = PgPoolOptions::new()
.max_connections(10)
.connect_with(opts)
.await
.expect("PgPool");
sqlx::query("drop table if exists sqlx_issue").execute(&pool).await.unwrap();
sqlx::query("create table sqlx_issue (name varchar(255))").execute(&pool).await.unwrap();
sqlx::query("insert into sqlx_issue (name) values ('issue')").execute(&pool).await.unwrap();
let row = sqlx::query("select name from sqlx_issue").fetch_optional(&pool).await.unwrap();
println!("{:?}", row.unwrap().get::<String, _>(0));
{
let mut trans = pool.begin().await.unwrap();
// Call begin again()
trans.begin().await.unwrap();
trans.begin().await.unwrap();
trans.begin().await.unwrap();
sqlx::query("delete from sqlx_issue").execute(&mut *trans).await.unwrap();
trans.commit().await.unwrap();
}
let row = sqlx::query("select name from sqlx_issue").fetch_optional(&pool).await.unwrap();
// Succeeds with `use sqlx::Acquire`. Fails with `use sqlx::postgres::any::AnyConnectionBackend`
assert!(row.is_none());
}
A wrong |
That's why. The It needs to be accessible from the |
Ah that makes sense. Thanks for the explanation. I have added that as well as a comment. Thanks for the help! |
sqlx_postgres::any
Currently you can call
begin()
on a postgres transaction without causing an error.This causes errors such as: