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
fix(schema): Deprecated setting schema paths to primitive values #12832
Conversation
i am not too familiar with the code in question, but couldnt we just check also you may want to change it to deprecation warning instead of error for the 6.x branch and a error for 7.x (next major) or directly target the 7.x branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks. 👍
lib/schema.js
Outdated
@@ -615,6 +615,12 @@ Schema.prototype.add = function add(obj, prefix) { | |||
if (key === '_id' && val === false) { | |||
continue; | |||
} | |||
// Deprecate setting schema paths to primitive types (gh-7558) | |||
if (key !== '_id' && typeof val === 'boolean') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to key !== '_id' && ((typeof val !== 'object' && typeof val !== 'function') || val == null)
. Not sufficient to check for boolean, we want to disallow all primitives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I've added an extra case to handle primitives specified as strings, otherwise, tests like this were failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
fix #7558
Summary
Prevent setting a
Schema
path to a boolean value by throwing an error.The issue refers to primitive types in general, let me know if the check needs to be extended to other types or refactored in some way.