spring-projects / spring-projects/spring-data-rest

@version field value ignored when updating data [DATAREST-1329]

Open
#1,689 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.