Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Op.any does not work when typeValidation = true #10463

Open
simonbrent opened this issue Feb 21, 2019 · 2 comments
Open

Op.any does not work when typeValidation = true #10463

simonbrent opened this issue Feb 21, 2019 · 2 comments

Comments

@simonbrent
Copy link

simonbrent commented Feb 21, 2019

What are you doing?

const sequelize = new Sequelize('database', 'username', 'password', { typeValidation: true });
const model = sequelize.define('foo', {
  id: { type: Sequelize.INTEGER }
});
model.findAll({ where: { id: { [Sequelize.Op.any]: [1,2] } } }).then(console.log);

What do you expect to happen?

Records 1 and 2 are logged

What is actually happening?

Unhandled rejection SequelizeValidationError: [1,2] is not a valid integer
at INTEGER.validate (node_modules/sequelize/lib/data-types.js:175:11)
at Object.escape (node_modules/sequelize/lib/dialects/abstract/query-generator.js:917:26)
at Object._whereParseSingleValueObject (node_modules/sequelize/lib/dialects/abstract/query-generator.js:2387:49)
...

This is because the escape function in query-generator requires options.isList to be true for an array value to be correctly validated, but on line 2387 it is called without any options: this.escape(value, field).
The same is true for Op.all. On lines 2418 and 2422, escape is called for Op.any/Op.all with isList = true, but these lines only apply to ANY/ALL conditions which are nested, e.g.

{ where: { [Sequelize.Op.not]: { id: { [Sequelize.Op.any]: [ 1, 2 ] } } }

Dialect: postgres
Dialect version: 10
Sequelize version: 4.42.0
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.

@reezer
Copy link

reezer commented Jul 16, 2019

This is not just related to typeValidation cases. This is a fixed minimal example (id missing in the above):

const model = sequelize.define('user', {
  id: {
    type: Sequelize.INTEGER,
    primaryKey: true,
  }
}, {
    tableName: 'users',
    underscored: true,
  });

model.findOne({
  where: {
    id: { [Sequelize.Op.any]: [1, 2] }
  }
}).then(console.log);

In 4.37.10 this is still working.

@simonbrent
Copy link
Author

Urgh, sorry about that. Fixed my initial comment.

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

No branches or pull requests

5 participants