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

`get_result` return err `NotFound` when upsert on_conflict do_nothing #952

Closed
zhangsoledad opened this Issue Jun 16, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@zhangsoledad

zhangsoledad commented Jun 16, 2017

  • diesel 0.13.0

  • rust 1.18 stable

User<'a> {
   name: &'a str
}

fn save(user: User) -> Result {
    match diesel::insert(&user.on_conflict(users::name, do_nothing()))
                .into(users::table)
                .get_result::<User>(conn) {
        Ok(_) => Ok(()),
        Err(e) => {
            debug!("save user {:?}", e);
            Err(e)
        }
    }
}

save(User{name: "123"}).unwrap(); //ok
save(User{name: "123"}).unwrap(); //wrong get NotFound

is this by design?

@sgrif

This comment has been minimized.

Member

sgrif commented Jun 17, 2017

It's a bit of a quirky interaction between those two features, but yeah it's by design. I don't think that specifically passing an upsert with do_nothing to insert should change the return type of get_result, as that's a really non-local change. You should call .optional here if you want a QueryResult<Option<User>> as per the docs

@sgrif sgrif closed this Jun 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment