fix: remove callback from callbacks if Remove() called#6916
Merged
jinzhu merged 3 commits intogo-gorm:masterfrom Mar 26, 2024
Merged
fix: remove callback from callbacks if Remove() called#6916jinzhu merged 3 commits intogo-gorm:masterfrom
callback from callbacks if Remove() called#6916jinzhu merged 3 commits intogo-gorm:masterfrom
Conversation
a631807682
reviewed
Mar 20, 2024
Member
a631807682
left a comment
There was a problem hiding this comment.
Maybe we can reduce the number of loops through map ?
Contributor
Author
|
Thanks! I have improved the part you mentioned in your comment. |
a631807682
approved these changes
Mar 25, 2024
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.
What did this pull request do?
ref: #6910 (review)
Modified the
Remove()method so that it not only sets the removed flag but also removes thecallbackfrom thecallbackswithincompile().This resolves the following issues:
Get()method could retrieve callbacks that have already been removed.Remove()method.In addition, I have made some modifications to the existing tests.
Previously, the specified
beforeandafterfor acallbackcontinued to affect the overall order even after beingRemove()d. I believe that continuing to have an effect after being removed is an unintended behavior.What do you think? I would appreciate any advice.
User Case Description
The problem where the
Get()methodIf a callback named
cb1is registered, it is expected that callingGet("cb1")afterRemove("cb1")should returnnil. However, a callback function registered ascb1is being returned instead.The problem where the
Remove()methodThe expectation is that callbacks marked as removed via
Remove()should not be executed. However, we encountered an issue where callbacks registered through methods likeBefore("*").Register()continue to operate even after beingRemove()d.This typically occurs in scenarios such as the following:
workaround
For your reference, using
Before("*").Remove()can be mentioned as a workaround for the above issue.