sequelize / sequelize/sequelize

Updating a Model with custom validation bug

Open
#13,432 21 comments 1 reaction 1 assignee View on GitHub

@ephys is already working on this.

Since Jan 22, 2022.

breaking change type: bug
Dominant language
TypeScript
Stars
30.4k
Forks
4.3k
Avg merge
1d 6h
Merged PRs (30d)
68

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.