apache / apache/grails-core

Optimistic Locking not working for Edit

Open
#11,712 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Task List

- [x] Steps to reproduce provided
- [ ] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)

### Steps to Reproduce

1. Edit an existing entity by two users in parallel (Can be simulated by using two different browsers)
2. Both users are in the edit mode and both users are changing some properties of the entity
3. User 1 clicks the save button and the entity is updated in the database
4. User 2 clicks the save button and the entity is updated in the database and the changes from User 1 are overwritten

### Expected Behaviour
User 2 should not be able to store the entity, because User 1 has already changed the entity.
Both users had the same version count in the UI when editing the entity and therefor an optimistic lock exception should occur.

### Actual Behaviour
No exception occur and no one gets notified.

### Environment Information

- **Operating System**: Ubuntu Linux 20.04
- **Grails Version:** 4.0.6 (also tested with 4.0.3)
- **JDK Version:** 11.0.8+10

### Example Application
https://github.com/tobiaskraft/VersionBug

The sample application is configured with a postgres database driver. The connection and database driver has to be adjusted.

Steps for reproducing the problem in the sample application:
* The application contains the PersonController and the Person entity for simulating the problem
* First create a new person entry
* Edit the person entry
* Go to another browser and also edit the same entry
* Afterwards save both entries.
* The last saved entry will "win"

Please see the comment in the method `PersonController.update()`. The problem seems to be the domain class parameter of the method. The version is there already overwritten.

Contributor guide

Open the contributing guide

Research direction

Start with the linked VersionBug example, the Person entity, and PersonController.update(), especially the comment about the domain class parameter. Reproduce two concurrent edits using the stated browser steps and inspect how the version value is handled during update. Done means the second save is rejected with an optimistic lock exception instead of overwriting the first user's changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.