Skip to content

kurtbuilds/fetch-one-bug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reproduction repo for launchbadge/sqlx#1370

Run with just run

The error is caused by improper handling of DEFERRABLE INITIALLY DEFERRED constraints.

That constraint is created in create_table_posts.sql. Remove the DEFERRABLE INITIALLY DEFERRED part and the error goes away.

The solution is that fetch_one needs to check whether the connection has been made dirty.

Issue includes a workaround, to explicitly not use .fetch_one, since it's broken in this situation, and instead use .fetch

async fn main() {
    let mut stream = sqlx::query_as("insert into bar values ('foo') returning *").fetch(&pool);

    let bar: Bar = stream.try_next().await?.ok_or(sqlx::Error::RowNotFound)?;
    // check for deferred FK constraint error
    stream.try_next().await?;
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published