Skip to content

Commit

Permalink
Ensure retryRoutines are only used for prepared statements - fixes #830
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Mar 20, 2024
1 parent 2b85ea7 commit 3e28f3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
const error = Errors.postgres(parseError(x))
query && query.retried
? errored(query.retried)
: query && retryRoutines.has(error.routine)
: query && query.prepare && retryRoutines.has(error.routine)
? retry(query, error)
: errored(error)
}
Expand Down
15 changes: 15 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,21 @@ t('Recreate prepared statements on RevalidateCachedQuery error', async() => {
]
})

t('Properly throws routing error on not prepared statements', async() => {
await sql`create table x (x text[])`
const { routine } = await sql.unsafe(`insert into x(x) values (('a', 'b'))`).catch(e => e)

return ['transformAssignedExpr', routine, await sql`drop table x`]
})

t('Properly throws routing error on not prepared statements in transaction', async() => {
const { routine } = await sql.begin(sql => [
sql`create table x (x text[])`,
sql`insert into x(x) values (('a', 'b'))`,
]).catch(e => e)

return ['transformAssignedExpr', routine]
})

t('Catches connection config errors', async() => {
const sql = postgres({ ...options, user: { toString: () => { throw new Error('wat') } }, database: 'prut' })
Expand Down

0 comments on commit 3e28f3a

Please sign in to comment.