Skip to content

retrying queries with bind/replacement/more fails #10453

Closed

Description

@yocontra

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.

Activity

  1. yocontra commented on Feb 17, 2019

    @yocontra
    ContributorAuthor

    Here's how we fixed it on our fork: yocontra@f6a2e2e

    Tried not to touch anything we didn't need to - IMO this whole block probably needs to be revisited/cleaned up, it looks like a few other issues might exist in there.

  2. added
    type: bug
    on Mar 3, 2019
  3. yocontra commented on Mar 3, 2019

    @yocontra
    ContributorAuthor

    Thank you @sushantdhiman 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions