{"action":"created","issue":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/867","labels_url":"https://api.github.com/repos/balderdashy/waterline/issues/867/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/waterline/issues/867/comments","events_url":"https://api.github.com/repos/balderdashy/waterline/issues/867/events","html_url":"https://github.com/balderdashy/waterline/issues/867","id":59306067,"number":867,"title":"`required: false` prevents all other validators from running, even when attribute has non-null value","user":{"login":"cspotcode","id":376504,"avatar_url":"https://avatars.githubusercontent.com/u/376504?v=3","gravatar_id":"","url":"https://api.github.com/users/cspotcode","html_url":"https://github.com/cspotcode","followers_url":"https://api.github.com/users/cspotcode/followers","following_url":"https://api.github.com/users/cspotcode/following{/other_user}","gists_url":"https://api.github.com/users/cspotcode/gists{/gist_id}","starred_url":"https://api.github.com/users/cspotcode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cspotcode/subscriptions","organizations_url":"https://api.github.com/users/cspotcode/orgs","repos_url":"https://api.github.com/users/cspotcode/repos","events_url":"https://api.github.com/users/cspotcode/events{/privacy}","received_events_url":"https://api.github.com/users/cspotcode/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/balderdashy/waterline/labels/bug","name":"bug","color":"800000"},{"url":"https://api.github.com/repos/balderdashy/waterline/labels/needs%20failing%20test","name":"needs failing test","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-02-27T22:49:02Z","updated_at":"2015-04-28T14:50:41Z","closed_at":null,"body":"When I set `required: false` in a model attribute's configuration, none of the other validations run, even when I am setting the attribute to a non-null, non-undefined value.\r\n\r\nFor example:\r\n```\r\n// here's your model config for User\r\nmodule.exports = {\r\n    //...\r\n    attributes: {\r\n        secondaryEmail: {\r\n            required: false,\r\n            email: true // this validation will not execute\r\n        }\r\n    }\r\n    //...\r\n}\r\n \r\n// and you try to do this\r\nUser.update({id: userId}, {\r\n    secondaryEmail: 'not an email' // should be rejected by \"email\" validator\r\n}).exec(function(err, updated) {\r\n    assert(err == null); // the update succeeded.  Is this intended behavior?\r\n    //...\r\n});\r\n```\r\n\r\nHere is the relevant waterline source code:\r\nhttps://github.com/balderdashy/waterline/blob/master/lib/waterline/core/validations.js#L132-141\r\n\r\nIs this intended behavior or a bug?"},"comment":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/comments/97091370","html_url":"https://github.com/balderdashy/waterline/issues/867#issuecomment-97091370","issue_url":"https://api.github.com/repos/balderdashy/waterline/issues/867","id":97091370,"user":{"login":"dmarcelino","id":1280446,"avatar_url":"https://avatars.githubusercontent.com/u/1280446?v=3","gravatar_id":"","url":"https://api.github.com/users/dmarcelino","html_url":"https://github.com/dmarcelino","followers_url":"https://api.github.com/users/dmarcelino/followers","following_url":"https://api.github.com/users/dmarcelino/following{/other_user}","gists_url":"https://api.github.com/users/dmarcelino/gists{/gist_id}","starred_url":"https://api.github.com/users/dmarcelino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmarcelino/subscriptions","organizations_url":"https://api.github.com/users/dmarcelino/orgs","repos_url":"https://api.github.com/users/dmarcelino/repos","events_url":"https://api.github.com/users/dmarcelino/events{/privacy}","received_events_url":"https://api.github.com/users/dmarcelino/received_events","type":"User","site_admin":false},"created_at":"2015-04-28T14:50:41Z","updated_at":"2015-04-28T14:50:41Z","body":"This definitely looks wrong...\r\n``` javascript\r\n    // if required is set to 'false', don't enforce as required rule\r\n    if (curValidation.hasOwnProperty('required')&&!curValidation.required) {\r\n        return cb();\r\n    }\r\n```\r\n\r\nAccording to @stensrud:\r\n\r\n> ```javascript\r\n>     // If value is not required and empty then don't\r\n>     // try and validate it\r\n>     if(!curValidation.required) {\r\n>       if(value === null || value === '') return cb();\r\n>     }\r\n> ```\r\n> \r\n> This code, present just above my commit, have the same intention. Tried to remove my commit, and it seems to work now.\r\n\r\nSo I think we can safely remove the offending lines of code and add a test to prevent regressions."}}