porsager / porsager/postgres

Deferred constraint errors not properly detected

Open
#1,117 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the deferred-constraint insert shown in the issue, first without an explicit transaction and then inside sql.begin(). Compare whether each form rejects its promise; done means the standalone INSERT reports the constraint error consistently, like the explicit transaction case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.