spring-projects / spring-projects/spring-data-rest
@version field value ignored when updating data [DATAREST-1329]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
asifbakht opened DATAREST-1329 and commented
I have a model with field @version annotation. When data is sent with wrong version number to service it goes through different process and a proper version is set to model payload content. That should not be the case, version should not be controlled by spring framework but it should throw exception if user send wrong version number (higher or lower from current record version in database).
I investigated and debug on RepositoryEntityController and verified that @version field sent from client side is ignored before saving content into database.
Before RepositoryEntityController the payload content is passed to PersistentEntityResource where it fetches the existing record from database and merge new content into old record.
After going more deeply I found that DomainObjectReader class function doWithPersistentProperty modifies old record content with new content one but ignores version field and let the old version remain intact.
If this is scenario then it will never throw Optimisitc Lock exception
Between I am using spring-data-rest-webmvc-2.6.7 with MongoDB
Affects: 3.1.3 (Lovelace SR3)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.