Skip to content
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

[Regression][SQLite] Insert + On Conflict Do Nothing = error #1549

Closed
andoriyu opened this issue Mar 17, 2023 · 1 comment
Closed

[Regression][SQLite] Insert + On Conflict Do Nothing = error #1549

andoriyu opened this issue Mar 17, 2023 · 1 comment

Comments

@andoriyu
Copy link

Description

In SeaORM prior 0.11, running the following query twice works fine:

INSERT INTO \"group_user_membership\" (\"user_id\", \"group_id\") VALUES ('01GVEMDSKK33QX8ET4601B4HG7', '00000000000000000000000000') ON CONFLICT (\"group_id\", \"user_id\") DO NOTHING"

Running it on 0.11.x results in DbErr::RecordNotInserted

Steps to Reproduce

  1. Insert a record
  2. Insert a conflicting record instructing to do nothing on conflict

Expected Behavior

No error, not records inserted.

Actual Behavior

Get an error: DbErr::RecordNotInserted

Reproduces How Often

Every single time.

Workarounds

Check for DbErr::RecordNotInserted prior bubbling error up the stack.

Reproducible Example

https://github.com/andoriyu/seaorm-issues/blob/main/src/lib.rs#L39-L53

Versions

0.11.0 and 0.11.1

@tyt2y3
Copy link
Member

tyt2y3 commented Mar 20, 2023

Thanks for the question.

It was an intentionally introduced change. For now, you can match the result to distinguish different cases:

match result {
    Ok(r) => Ok(Some(r)),
    Err(DbErr::RecordNotInserted) => Ok(None),
    Err(e) => Err(e),
}

In the future we might add a convenience method for it.

@tyt2y3 tyt2y3 closed this as completed Mar 20, 2023
@tyt2y3 tyt2y3 mentioned this issue Jun 21, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants