Skip to content

[db] Audit usage of "ON CONFLICT DO NOTHING RETURNING ..."  #1168

Open
@smklein

Description

@smklein

(here's some background that covers this use-case)

There are a handful of spots in the datastore where we:

  • INSERT INTO a table,
  • ON CONFLICT, DO NOTHING
  • and have a RETURNING clause

Example:

let instance: Instance = diesel::insert_into(dsl::instance)
.values(instance)
.on_conflict(dsl::id)
.do_nothing()
.returning(Instance::as_returning())

This is valid SQL, but it's a little suspect:

  • If there are no conflicts (we're inserting the object with the UUID for the first time) we get the value that we intended to insert.
  • However, if there are conflicts, this group of statements does not return any rows. Instead, it results in a NotFound error from the database.

This means that, especially in situations where we expect idempotency, this statement may return different results if invoked multiple times.

Metadata

Metadata

Assignees

No one assigned

    Labels

    databaseRelated to database access

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions