-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
This was a hard one to track down, I've been seeing this error for months and finally figured out why. I can attempt a PR but it would probably be quicker for the maintainers to take this.
Issue
Any query that uses bind will fail permanently on every retry. The reason for this is actually pretty simple: https://github.com/sequelize/sequelize/blob/master/lib/sequelize.js#L509-L520
On the first attempt, the sql variable is mutated so that $id becomes $1. On the second attempt, it uses the mutated SQL which treats it as an array bind - but the values passed is still an object.
The fix is to remove all mutating of outer scope variables from any retry function, so that if a retry needs to occur it is using the same inputs and not anything mutated by the last attempt.
What do you expect to happen?
It should retry without failing.
What is actually happening?
Error: Named bind parameter "$1" has no value in the given object.
at sql.replace (/Users/contra/Projects/staeco/node_modules/sequelize/lib/dialects/abstract/query.js:85:15)
at String.replace (<anonymous>)
at Function.formatBindParameters (/Users/contra/Projects/staeco/node_modules/sequelize/lib/dialects/abstract/query.js:67:22)
at Function.formatBindParameters (/Users/contra/Projects/staeco/node_modules/sequelize/lib/dialects/postgres/query.js:51:27)
at Promise.try (/Users/contra/Projects/staeco/node_modules/sequelize/lib/sequelize.js:499:44)
Dialect: postgres (but also any)
Database version: 11.1
Sequelize version: v4 and v5
Tested with latest release: Yes
Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.