fix(document): avoid using childSchemas.path for compatibility with pre-Mongoose-8.8 schemas#15131
Merged
fix(document): avoid using childSchemas.path for compatibility with pre-Mongoose-8.8 schemas#15131
Conversation
…re-Mongoose-8.8 schemas Fix #15071
hasezoey
approved these changes
Dec 28, 2024
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); |
Collaborator
There was a problem hiding this comment.
Should this workaround be reverted for the next major version?
If it should, maybe consider adding a TODO or some other kind of reminder.
Collaborator
Author
There was a problem hiding this comment.
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; | ||
| } |
Collaborator
There was a problem hiding this comment.
Maybe this should get a test?
Collaborator
Author
There was a problem hiding this comment.
This code is covered by the tests added in the PR, albeit indirectly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.pathproperty 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