-
-
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
Fix ObjectId instanceof
checks
#11891
Fix ObjectId instanceof
checks
#11891
Conversation
92b1d42
to
d111309
Compare
Can you add the unit test to avoid again an regression? |
Sure thing, @Uzlopak. Where should I put it? I was going to add that example test to this MR, and started putting it in |
Just create a schema.objectid.test.js. there is currently not a very strict Organisation. It is more important to have a test |
Good thing you asked for a test. I can't recreate this issue in this repo, but I keep getting this error in my repository with the exact same test code: const result = await TestModel.insertMany([
EJSON.deserialize({ name: 'Document 1', owner: { $oid: '6005c0bb52e4d267b5d96009' } })
]);
So there's something weird going on in my repository where the |
d111309
to
a84498e
Compare
PR Automattic#11841 changed a whole bunch of checks for `instanceof ObjectId` to use the `isBsonType()` function instead. Unfortunately some were missed in the `./lib/schema/objectid.js` file. Convert the remaining `instanceof` checks in `objectid.js` to use the `isBsonType()` check instead so that all `ObjectId`s created from any `bson` modules should validate/cast properly. This was found because my nested document with required ObjectIds started failing validation when I loaded the documents from JSON files in my tests using `bson.EJSON` after the release of 6.3.4 -> 6.3.5.
a84498e
to
e980737
Compare
Sorry, @Uzlopak. I can't build a test in this repo that fails before my fix. As @coyotte508 said in the original MR #11841 , this issue is caused by having different instances of I tried to hack together a test where I tried to artificially break |
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! 👍
@AbdelrahmanHafez why did you merge this? |
Summary
PR #11841 changed a whole bunch of checks for
instanceof ObjectId
touse the
isBsonType()
function instead. Unfortunately some were missedin the
./lib/schema/objectid.js
file.Convert the remaining
instanceof
checks inobjectid.js
to use theisBsonType()
check instead so that allObjectId
s created from anybson
modules should validate/cast properly.This was found because my nested document with required ObjectIds
started failing validation when I loaded the documents from JSON files
in my tests using
bson.EJSON
after the release of 6.3.4 -> 6.3.5.Examples
This test when run in a project that depends on
mongoose
andbson
will fail before this fix and work afterward.