Fix for @version field value ignored when updating data. - #2603
Open
ruthst00 wants to merge 1 commit into
Open
Conversation
…ating data. Signed-off-by: ruthes00 <ruthes00@gmail.com>
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.
Fixes #1689
Root Cause
In
DomainObjectReader.doMerge()(used for HTTP PATCH / JSON Merge Patch), the version field sent by the client was being silently stripped from the JSON node before Jackson applied it to the target object. This happened becauseMappedJacksonProperties.isWritableField()returnsfalsefor version properties, anddoMerge()removes any non-writable field from the JSON node:As a result, the existing version from the database was always kept, so the underlying store's optimistic locking mechanism never saw a version mismatch — even when the client sent a wrong version number.
Fix
DomainObjectReader.doMerge()— Instead of unconditionally removing all non-writable fields, the fix checks if the non-writable field is the version property. If it is, the field is kept in the JSON node so Jackson can apply it to the target object, enabling the store's optimistic locking to detect mismatches. The id field is still stripped to prevent clients from changing resource identity.Behavior preserved
retainIdentifierAndVersion()still overwrites the client's version with the server's version before deserialization, so PUT cannot mutate the version (existing testsdoesNotWipeIdAndVersionPropertyForPutanddoesNotAllowMutatingIdAndVersionViaPutBodystill pass).JsonPointerMapping.forWrite()still rejects writes to the version property via JSON Patch operations (existing testforWriteRejectsVersionPropertystill passes).OptimisticLockExceptionon version mismatch.Tests added
Two new tests in
DomainObjectReaderUnitTests:appliesVersionFromClientForPatch()— verifies the version from the client is applied during PATCHdoesNotAllowMutatingVersionViaPutBody()— verifies the version cannot be changed via PUT