You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fields with settings "required : undefined" are required #8219
Do you want to request a feature or report a bug?
I think this a bug.
If it is by design, I would be very curious as to why, as it seem misleading to me.
then the schema Throw with the error "Cannot read property 'message' of null
What is the expected behavior?
I would expect both a field marked with "required : undefined" or "required : null" to simply not be required, as their are falsy value and by default, if "required" is not set, it is "false".
this cause a subtle bug where if I have different biaviour depending if I have an object without the property "required" or if I have it but with value "undefined".
At most, I would expect that if we don't want for null and undefined value to be concidered as "falsy", we could throw a meaningfull message.
For null, the error is there because at schematype.js:791, there is the line if(typeof required === 'object'), letting pass the "null" value as it was an object.
For undefined, the error is because at schematype.js:797, there is the line if(required === false), not permitting undefined nor null.
do note, I don't know what to do if the value send is a string or number. Common sens would be probably to let normal javascript rules for coercion (so changing line 797 for if(!!required === false), and let a non-empty string or non-zero number be true, and an empty string or 0 be false.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Activity
test(schema): repro #8219