不要怂,就是干,撸起袖子干!

Commit bc6922c7 by Sushant Committed by GitHub

Fix: custom msg not used for notNull validations (#6943)

* fix: custom msg not used for notNull validations

* [ci skip] changelog
1 parent 5efd5cd2
Showing with 8 additions and 3 deletions
# Future # Future
- [FIXED] Custom error message not used for `notNull` validation [#6531](https://github.com/sequelize/sequelize/issues/6531)
- [FIXED] N:M `through` option naming collisions [#4597](https://github.com/sequelize/sequelize/issues/4597) - [FIXED] N:M `through` option naming collisions [#4597](https://github.com/sequelize/sequelize/issues/4597)
[#6444](https://github.com/sequelize/sequelize/issues/6444) [#6444](https://github.com/sequelize/sequelize/issues/6444)
- [CHANGED] Updated deprecated `node-uuid` package to `uuid` [#6919](https://github.com/sequelize/sequelize/pull/6919) - [CHANGED] Updated deprecated `node-uuid` package to `uuid` [#6919](https://github.com/sequelize/sequelize/pull/6919)
......
...@@ -304,14 +304,18 @@ class InstanceValidator { ...@@ -304,14 +304,18 @@ class InstanceValidator {
_validateSchema(rawAttribute, field, value) { _validateSchema(rawAttribute, field, value) {
let error; let error;
if (rawAttribute.allowNull === false && ((value === null) || (value === undefined))) { if (rawAttribute.allowNull === false && (value === null || value === undefined)) {
error = new sequelizeError.ValidationErrorItem(field + ' cannot be null', 'notNull Violation', field, value); const validators = this.modelInstance.validators[field];
const errMsg = validators
? (validators.notNull || {}).msg
: `${field} cannot be null`;
error = new sequelizeError.ValidationErrorItem(errMsg, 'notNull Violation', field, value);
this.errors.push(error); this.errors.push(error);
} }
if (rawAttribute.type === DataTypes.STRING || rawAttribute.type instanceof DataTypes.STRING || rawAttribute.type === DataTypes.TEXT || rawAttribute.type instanceof DataTypes.TEXT) { if (rawAttribute.type === DataTypes.STRING || rawAttribute.type instanceof DataTypes.STRING || rawAttribute.type === DataTypes.TEXT || rawAttribute.type instanceof DataTypes.TEXT) {
if (Array.isArray(value) || (_.isObject(value) && !value._isSequelizeMethod) && !Buffer.isBuffer(value)) { if (Array.isArray(value) || (_.isObject(value) && !value._isSequelizeMethod) && !Buffer.isBuffer(value)) {
error = new sequelizeError.ValidationErrorItem(field + ' cannot be an array or an object', 'string violation', field, value); error = new sequelizeError.ValidationErrorItem(`${field} cannot be an array or an object`, 'string violation', field, value);
this.errors.push(error); this.errors.push(error);
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!