apache / apache/grails-core

minSize validation does not validate correctly on collections

Open
#14,529 3 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

### Steps to Reproduce

1. define following domain class

class mytest {
def my_data = "123"
static hasMany = [childItems: mytest]
static constraints = {
childItems minSize: 1
}
}
2. execute the following code

def mytest = new mytest()
mytest.save(failOnError: true, flush: true)
def result = mytest.validate()

### Expected Behaviour
According http://docs.grails.org/3.1.1/ref/Constraints/minSize.html

minSize: Sets the minimum size of a **collection** or number property

Hence _result_ should be false

### Actual Behaviour

_result_ is true

### Environment Information

- **Operating System**: Ubuntu 16.04
- **GORM Version:** gormVersion=6.1.10.RELEASE
- **Grails Version (if using Grails):** 3.3.8
- **JDK Version:** 1.8.0_201

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the `mytest` domain class, its `hasMany` collection, and the `validate()` call shown in the report. Start by tracing how GORM handles `minSize` for collection constraints. Done means an empty `childItems` collection makes validation return false and a regression test covers the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.