apache / apache/grails-core

Unique constraint ignores transient group in parent/child save

Open
#14,532 0 comments 0 reactions 0 assignees View on GitHub
relates-to: gorm
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Task List

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

### Steps to Reproduce

1. Clone the example repo:
https://github.com/rmorrise/grails-unique-child
2. `grails run-app`
3. POST the following JSON data:
`http://localhost:8080/MasterThing`
`Content-Type application/json`
```
{
"details": [
{
"itemName": "Foo"
}
]
}
```
4. Repeat the same POST request again.

### Expected Behaviour

Both requests should be OK.

Validation of the `unique` constraint on `DetailItem` should be scoped to the master object that is being posted.

### Actual Behaviour

HTTP error 422:
`Property [itemName] of class [class grails.unique.child.DetailItem] with value [Foo] must be unique`

The `unique` constraint is validated globally for the `itemName` properly only.

### Environment Information

- **Operating System**: Windows 7 x64
- **GORM Version:** 6.1.10.RELEASE
- **Grails Version (if using Grails):** 3.3.8
- **JDK Version:** 1.8.0_121

### Example Application

- https://github.com/rmorrise/grails-unique-child

Contributor guide

Open the contributing guide

Research direction

Start with the linked grails-unique-child example and reproduce the issue by running the app and repeating the documented POST to /MasterThing. Then inspect the GORM unique-constraint validation involved in saving the parent and child; done means repeated requests succeed and DetailItem.itemName is scoped to its master object.

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.