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

change: remove deprecation from notNull for custom messages / enforce use of allowNull with this validator #9549

Merged
merged 3 commits into from Jun 19, 2018

Conversation

sushantdhiman
Copy link
Contributor

…lowNull usage with it

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Fixes #1500

Sequelize can customize allowNull error messages with notNull validator, but validator throw error when value is not null due to deprecation for notNull.

I have removed that deprecation, it was only introduced to enforce users to use allowNull over notNull, I have added some checks that will only allow use of notNull with allowNull: false.

So overall if users want to prevent null values they can as usual use allowNull: false, but if they want to customize that error message, they can use notNull.msg

@codecov
Copy link

codecov bot commented Jun 17, 2018

Codecov Report

Merging #9549 into master will increase coverage by 0.01%.
The diff coverage is 87.5%.

validator.notNull = function() {
throw new Error('Warning "notNull" validation has been deprecated in favor of Schema based "allowNull"');
validator.notNull = function(val) {
return [null, undefined].indexOf(val) === -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since v5 targets NodeJS 6+ it's now possible to return [null, undefined].includes(val)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I just copied this code from old PR, will change

@sushantdhiman sushantdhiman merged commit 7525ef0 into master Jun 19, 2018
@sushantdhiman sushantdhiman deleted the fix-1500 branch June 19, 2018 03:00
@dydome
Copy link

dydome commented Jun 22, 2018

@sushantdhiman when those changes will be online with the latest npm varsion?

@sushantdhiman
Copy link
Contributor Author

Next beta release 5.0.0-beta.9 this weekend

}

if (attribute.allowNull !== false && _.get(attribute, 'validate.notNull')) {
throw new Error(`Invalid definition for "${this.name}.${name}", "notNull" validator is only allowed with "allowNull:false"`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great change for developer UX 👍 @sushantdhiman

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

Successfully merging this pull request may close these issues.

None yet

4 participants