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

@sushantdhiman sushantdhiman commented Jun 17, 2018

…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

@sushantdhiman sushantdhiman requested review from janmeier and eseliger Jun 17, 2018
@codecov
Copy link

@codecov 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;

This comment has been minimized.

@Alexsey

Alexsey Jun 17, 2018
Contributor

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

This comment has been minimized.

@sushantdhiman

sushantdhiman Jun 17, 2018
Author Contributor

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

@sushantdhiman sushantdhiman merged commit 7525ef0 into master Jun 19, 2018
3 of 4 checks passed
3 of 4 checks passed
codecov/patch 87.5% of diff hit (target 96.03%)
Details
codecov/project 96.04% (+0.01%) compared to fba11ce
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@sushantdhiman sushantdhiman deleted the fix-1500 branch Jun 19, 2018
@dydome
Copy link

@dydome dydome commented Jun 22, 2018

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

@sushantdhiman
Copy link
Contributor Author

@sushantdhiman sushantdhiman commented Jun 22, 2018

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"`);

This comment has been minimized.

@contra

contra Jul 15, 2018
Contributor

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
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants