sequelize: Updating a Model with custom validation bug

Issue Creation Checklist

Bug Description

When trying to Model.update() a model with custom validation, an error is thrown as the custom validator does not have access to instance fields.

SSCCE

**Here is the link to the SSCCE for this issue: https://github.com/gsqrt2/sequelize-update-validation-error

What do you expect to happen?

In regard to the SSCCE:

Connection.update( {
        approved: true
    }, {
    where: {
        approved: false
    }
})

should update Connections where approved===false to approved: true

What is actually happening?

The custom validator throws, as instance dataValues are undefined

ValidationError [SequelizeValidationError]:  Validation error: Cannot connect to self.

Additional context

The SSCCE is extremely basic, just a dummy Connection with a custom validator that ensures that the two user ids are not equal. Commenting out the validation restores normal functionality.

Environment

  • Sequelize version: 6.6.5
  • Node.js version: v12.19.0

Bug Report 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):
  • 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.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 21 (11 by maintainers)

Most upvoted comments

I see. That could have been intended but if indivualHooks is used, I think it makes more sense to run validation on each instance one by one.

Changing it in v6 could break some users but we’re actively working on v7 right now so if someone wants to open a PR to change the behavior in v7 (main branch), we can include it before the first stable release

There’s a related open issue as well: #12666