E479 Deferred constraint errors not properly detected · Issue #1117 · porsager/postgres · GitHub
[go: up one dir, main page]

Skip to content

Deferred constraint errors not properly detected #1117

@arusakov

Description

@arusakov

When working with deferred constraints and performing inserts without an explicit transaction, postgres.js fails to properly detect when an error occurs.

// table_name contains DEFERRABLE INITIALLY DEFERRED constraint

// insert *value* object with property which breaks the constraint
await sql`INSERT INTO table_name ${sql(value)}`

// no error, no rejected promise

The error is only properly caught when using an explicit transaction with begin() and performing the insert inside the transaction block.

await sql.begin(async (sql) => {
  await sql`INSERT INTO table_name ${sql(value)}`
})
// rejected promise

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0