Skip to content
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(document): avoid using childSchemas.path for compatibility with pre-Mongoose-8.8 schemas #15131

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #15071

Summary

#15071 is a tricky situation where the user has a shared connection package that uses Mongoose 8.8, and a client npm package which defines schemas using Mongoose 8.5 but then defines models using the Mongoose 8.8 connection. And we added a new childSchemas.path property in 8.8.3 with #15029 that Mongoose 8.8.3 expects, but schemas from Mongoose 8.5 do not have.

The "right" solution is to tell the user to ensure a consistent version of Mongoose, because we cannot realistically test that schemas from every version of Mongoose work with models from every other version of Mongoose. However, in the interest of not breaking code that previously worked, we can use this PR's more backwards-compatible approach.

Examples

@vkarpov15 vkarpov15 added this to the 8.9.3 milestone Dec 26, 2024
Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Comment on lines +3708 to +3709
// Avoid using `childSchemas.path` to avoid compatibility versions with pre-8.8 versions of Mongoose
const val = doc.$__getValue(model.path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this workaround be reverted for the next major version?
If it should, maybe consider adding a TODO or some other kind of reminder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason to prioritize removing this workaround, unless the extra logic in getValue() for handling maps causes issues.

Comment on lines +634 to +636
if (part === '$*' && obj instanceof Map) {
return obj;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should get a test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is covered by the tests added in the PR, albeit indirectly.

@vkarpov15 vkarpov15 merged commit 0bf4563 into master Dec 30, 2024
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update from 8.8.2 to 8.8.3 causes "Uncaught TypeError: Invalid path. Must be either string or array"
3 participants