Skip to content

MSSQL: Upsert does not accept primary keys with a value of 0 or false. #11902

Closed

Description

@TorstenForth

Issue Description

Upsert does not accept primary keys with a value of 0 or false.

What are you doing?

I try to upsert a row into a table which has a composite primary key (a string and a boolean value).

Here is the link to the SSCCE for this issue: https://github.com/TorstenForth/sequelize-sscce/tree/patch-4

What do you expect to happen?

I expected that a row would be inserted also when the boolean part of the primary key was false.

What is actually happening?

An error is thrown. Message: Unique key should be passed to upsert query

Additional context

I think that the bug is in the file sequelize/lib/dialects/mssql/query-generator.js in the following code fragment (I have marked the bug with a comment):

    //Filter NULL Clauses
    const clauses = where[Op.or].filter(clause => {
      let valid = true;
      /*
       * Exclude NULL Composite PK/UK. Partial Composite clauses should also be excluded as it doesn't guarantee a single row
       */
      for (const key in clause) {
        if (!clause[key]) { /// ===> Bug: Should be 'if (clause != null)'
          valid = false;
          break;
        }
      }
      return valid;
    });

Environment

  • Sequelize version: 5.21.3
  • Node.js version: 10.16.3
  • Operating System: openSUSE 15.0

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s): MSSQL
  • I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.

Activity

  1. TorstenForth commented on Feb 5, 2020

    @TorstenForth
    Author

    ... should be if (clause == null)

  2. sushantdhiman commented on Jul 4, 2020

    @sushantdhiman
    Contributor

    🎉 This issue has been resolved in version 6.3.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions