Skip to content

"is" executes as "is not" #8816

Closed
Closed

Description

@rodic

What are you doing?

function delete(anId: number): Promise<number> {
  return Model.destroy({
    where: {
      anId,
      completedAt: { [Op.is]: null }
    }
  });
}

What do you expect to happen?

Executing (default): DELETE FROM "Models" WHERE "anId"= 55 AND "completedAt" IS NULL 

What is actually happening?

Executing (default): DELETE FROM "Models" WHERE "anId"= 55 AND "completedAt" IS NOT NULL 

Dialect: postgres
Dialect version:
Database version: 9.5.10
Sequelize version: 4.28.0
Tested with latest release: No (If yes, specify that version)

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. iamjoyce commented on Dec 26, 2017

    @iamjoyce

    FYI, You can use completedAt: { [Op.eq]: null } to get "completedAt" IS NULL

  2. rodic commented on Dec 26, 2017

    @rodic
    Author

    hi @iamjoyce thanks. yes, i'm using that.

  3. mccabemj commented on Jan 3, 2018

    @mccabemj
    Contributor

    @rodic no you are not. You are using Op.is. Use Op.eq for equal.

  4. iamjoyce commented on Jan 3, 2018

    @iamjoyce

    @mccabemj I think @rodic is using Op.eq for his system. He is right about the bug where Op.is translates to IS NOT in SQL statement, which is incorrect.

  5. mccabemj commented on Jan 3, 2018

    @mccabemj
    Contributor

    @iamjoyce sorry, I misunderstood the issue.

    @rodic I am actually able to recreate the issue and I think its a bug. Line 2392 of /sequelize/lib/dialects/abstract/query-generator.js

    I believe that should be
    } else if (value === null && comparator === this.OperatorMap[Op.ne]) {

    At the moment its evaluating that Op.ne is in the OperatorMap (which it obviously is) so using this.OperatorMap[Op.not]. It then never gets to line 2396 to use the IS.

    I'm new to GitHub, but I am actively trying to get involved, so would like to do a pull request if people confirm the bug.

  6. rodic commented on Jan 3, 2018

    @rodic
    Author

    @iamjoyce @mccabemj hey guys, sorry for the confusion. Op.is is buggy, I just pointed out that I'm using Op.eq as an alternative (as @iamjoyce proposed).

    @mccabemj having && this.OperatorMap[Op.ne]) looks buggy indeed. thanks for looking into this.

  7. mccabemj commented on Jan 4, 2018

    @mccabemj
    Contributor

    Added pull request to fix this - #8835

  8. sushantdhiman commented on Jan 4, 2018

    @sushantdhiman
    Contributor

    Fixed by 3397b23

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions