Skip to content

Commit 3e28f3a

Browse files
committed
Ensure retryRoutines are only used for prepared statements - fixes #830
1 parent 2b85ea7 commit 3e28f3a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/connection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
788788
const error = Errors.postgres(parseError(x))
789789
query && query.retried
790790
? errored(query.retried)
791-
: query && retryRoutines.has(error.routine)
791+
: query && query.prepare && retryRoutines.has(error.routine)
792792
? retry(query, error)
793793
: errored(error)
794794
}

tests/index.js

+15
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,21 @@ t('Recreate prepared statements on RevalidateCachedQuery error', async() => {
17891789
]
17901790
})
17911791

1792+
t('Properly throws routing error on not prepared statements', async() => {
1793+
await sql`create table x (x text[])`
1794+
const { routine } = await sql.unsafe(`insert into x(x) values (('a', 'b'))`).catch(e => e)
1795+
1796+
return ['transformAssignedExpr', routine, await sql`drop table x`]
1797+
})
1798+
1799+
t('Properly throws routing error on not prepared statements in transaction', async() => {
1800+
const { routine } = await sql.begin(sql => [
1801+
sql`create table x (x text[])`,
1802+
sql`insert into x(x) values (('a', 'b'))`,
1803+
]).catch(e => e)
1804+
1805+
return ['transformAssignedExpr', routine]
1806+
})
17921807

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

0 commit comments

Comments
 (0)