-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix(model): skip applying static hooks by default if static name conflicts with aggregate middleware #14904
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
Merged
vkarpov15
merged 3 commits into
Automattic:master
from
dragontaek-lee:skip-applying-static-hooks-aggregate-middleware
Sep 23, 2024
Merged
fix(model): skip applying static hooks by default if static name conflicts with aggregate middleware #14904
vkarpov15
merged 3 commits into
Automattic:master
from
dragontaek-lee:skip-applying-static-hooks-aggregate-middleware
Sep 23, 2024
Conversation
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
…licts with aggregate middleware
…atic name conflicts with aggregate middleware
2 tasks
vkarpov15
approved these changes
Sep 23, 2024
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 👍
And yes you can create a separate PR to apply this filtering to other middleware types. |
@vkarpov15 |
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 #14903
Summary
Make it so that if the custom static overwrites an existing aggregate middleware, don't apply middleware to it by default. This should be achieved by filtering custom static-named aggregates in
applyStaticHooks.js
.Furthermore, aside from this PR, I believe we should extend this filtering not only to query and aggregation middleware but also to other Mongoose middlewares, including Document and Model middleware. Does that make sense? If so, I would like to create another PR for this work.
Examples
Assume that the static method overwrites the built-in Mongoose aggregate function.
In this situation, also assume that there are pre and post hooks for aggregate.
With this PR, when a custom static method overwrites an existing aggregate middleware as described above, the middleware is not applied by default. As a result, the
this
context type in pre/post hooks is correctly set to Aggregate, as intended.