question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validator does not run if the field is not provided.

See original GitHub issue

Assume a very simple model:

var user = sequelize.define('user',
  {
    email: {
      type: DataTypes.STRING,
      validate: {
        isEmail: {
          msg: 'Email must be a valid email address'
        },
        notEmpty: {
          msg: 'Email is a required field'
        }
      }
    }
  })

If I do user.create({}) the validation rules in the email does not run. I am wondering why this is? The only thing I can see is, I am missing the schema validator allowNull: true however, this does not return an user friendly error message.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
BridgeARcommented, Mar 30, 2015

The validations won’t run, since the field is empty and this is a valid entry as long as you do not use allowNull: false (allowNull: true is the default value). So using allowNull: false is fixing your issue.

0reactions
loulincommented, May 24, 2016

If allowNull not set, all regular validations will not work for null attributes. But allowNull will add NOT NULL constraint on table schema which I don’t need. So how can I do builtinAttrValidate like notNull if allowNull is not set?

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Joi .custom() validator does not get executed on a ...
Now my problem is, that the custom validator does not get executed when I send in: { firstField: "test", }. But I want...
Read more >
Content validation | Looker - Google Cloud
The Content Validator searches your LookML for model, Explore, and field names referenced in your Looker content.
Read more >
Restrict data input by using validation rules - Microsoft Support
Validations rules help you check data as it is added to your Access desktop database which improves accuracy and consistency of data entry....
Read more >
Validate - Go Packages
The field under validation must be present and not empty only if any of the other specified fields are present. For strings ensures...
Read more >
Validators — WTForms Documentation (3.0.x) - Read the Docs
In-line validators are good for validating special cases, but are not easily reusable. If, in the example above, the name field were to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found