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

ValidationErrorItem value property does not contain "The value that generated the error" #3899

Closed
superclarkk opened this issue Jun 8, 2015 · 6 comments · Fixed by #6944
Closed
Labels
type: bug DEPRECATED: replace with the "bug" issue type

Comments

@superclarkk
Copy link
Contributor

According to the docs, the value property of the ValidationErrorItem(message, type, path, value) object should contain "The value that generated the error", but instead it contains the error message.

Database error {
   [SequelizeValidationError: Validation error: Password must be between 9 and 24 characters in length]
   name: 'SequelizeValidationError',
   message: 'Validation error: Password must be between 9 and 24 characters in length',
   errors: [ {
      message: 'Password must be between 9 and 24 characters in length',
      type: 'Validation error',
      path: 'password',
      value: 'Password must be between 9 and 24 characters in length',
      __raw: 'Password must be between 9 and 24 characters in length'
   } ]
}
@janmeier janmeier added the type: bug DEPRECATED: replace with the "bug" issue type label Jun 8, 2015
@janmeier
Copy link
Member

janmeier commented Jun 8, 2015

Can you provide a small test case?

@superclarkk
Copy link
Contributor Author

This bug is still outstanding, and exists for every validation. To confirm it, just set up a validation for any model, enter data so that it fails validation and console log the errors:

.catch(db.Sequelize.ValidationError, function(SequelizeValidationError){
    console.log("SequelizeValidationError: \n", JSON.stringify(SequelizeValidationError, null, 2));
})

@superclarkk
Copy link
Contributor Author

Please would you re-open this issue, or link it to an existing issue if it's a duplicate?

@mickhansen mickhansen reopened this Sep 15, 2015
@mickhansen
Copy link
Contributor

@superclarkk to help out you can add a model definition and call that triggers this.

@superclarkk
Copy link
Contributor Author

var User = sequelize.define('user',
    {
        first_name: {
            type: Sequelize.STRING,
            validate: {
                len: {
                    msg: "Must be between 4 and 24 characters",
                    args: [4, 24]
                }
        },
        last_name: { 
            type: Sequelize.STRING
        }
    }
);

User.sync()
    .then(function () {
        return User.create({
            first_name: 'Jon', // will fail validation as not between 4 and 24 chars
            last_name: 'Hancock'
        });
    })

    .catch(db.Sequelize.ValidationError, function(SequelizeValidationError){
        // note value attribute of error is not "Jon"
        console.log("SequelizeValidationError: \n", JSON.stringify(SequelizeValidationError, null, 2));
    });

@superclarkk
Copy link
Contributor Author

Note that schema validations seem to store the "value" property correctly - so, this bug only affects standard validations.

sushantdhiman added a commit that referenced this issue Dec 6, 2016
* fix: no value in built-in/custom validator

* using call rather than bind

* [ci skip] changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug DEPRECATED: replace with the "bug" issue type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants