GH-5166 - Apply BeforeConvertCallback result in MongoTemplate.replace()#5211
Open
SUJAY-HK wants to merge 1 commit into
Open
GH-5166 - Apply BeforeConvertCallback result in MongoTemplate.replace()#5211SUJAY-HK wants to merge 1 commit into
SUJAY-HK wants to merge 1 commit into
Conversation
…emplate.replace() Signed-off-by: SUJAY <hksujay03@gmail.com>
27af3c7 to
3ee0e1e
Compare
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.
to your changes. Don't submit any formatting related changes.
touched. Amend the date range in the Apache license header if
needed. For new types, add the license header (copy from another
file and set the current year only).
What
MongoTemplate.replace()andReactiveMongoTemplate.replace()callmaybeCallBeforeConvertbut the returned (potentially modified) entityis not used for BSON mapping.
replaceSingleContextwas already calledwith the original entity before the callback fires, so the callback
result is silently discarded.
Why
The
BeforeConvertCallbackcontract requires that the entity returnedby the callback is the one that gets mapped and persisted. The same
class of bug was previously fixed for
doInsert()in #2481.Fix
Move
maybeCallBeforeConvertbeforereplaceSingleContextinMongoTemplate.replace()so the post-callback entity is used fordocument mapping.
In
ReactiveMongoTemplate.replace(), wrap the context creation andcollection operation inside
.flatMap()on the callback result, sincemaybeCallBeforeConvertreturnsMono<T>in the reactive stack.Tests added in
MongoTemplateTestsandReactiveMongoTemplateTeststo verify the callback result is applied before the replacement is
persisted. Full test suite passes (6303 tests, 0 failures).
Closes #5166