-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
fields with settings "required : undefined" are required #8219
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
vkarpov15
added
the
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
label
Oct 7, 2019
vkarpov15
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Oct 7, 2019
This was referenced Oct 10, 2019
This was referenced Oct 10, 2019
This was referenced Mar 11, 2021
Open
This was referenced Mar 18, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is the current behavior?
if I create a schema like this
then the "name" field is required
also, if I set it like so
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 lineif(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 lineif(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.
I use mongoose 5.7.2 and Node 11.7.0
The text was updated successfully, but these errors were encountered: