apache / apache/grails-core

minSize constraint validates is true when null value is present

Open
#14,575 1 comment 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

- [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

These steps are true wether using domain objects or general validated objects

If you have a parent class and child class as follows
```
class Person implements Validateable {
String name

static constraints = {
name nullable: false
}
}

class Employer extends Person{
String company
List employees

static constraints = {
company nullable: false
employees minSize: 5
}
}
```

If you call `.validate()` on an this `Employer child = new Employer(name: 'TEST', company: 'TEST')` this will validate as true even when employees is null.

If you call `.validate()` on an this ```Employer child = new Employer(name: 'TEST', company: 'TEST')
child.employees = [employee1]``` this will validate as false as employees are less than 5.

If you call `.validate()` on an this ```Employer child = new Employer(name: 'TEST', company: 'TEST')
child.employees = [employee1, employee2, employee3, employee4, employee5]``` this well validate as true.

### Expected Behaviour

That when employees is null, validation fails due to the minimum number not being met.

### Actual Behaviour

That when employees is null, validation passes.

Note: if you want to produce expected behaviour it is possible by adding `nullable: false`
`employees nullable:false, minSize: 5`

### Environment Information

- **Operating System: MacOS 10.13.3
- **GORM Version: 6.1.9.RELEASE
- **Grails Version (if using Grails): 3.3.4
- **JDK Version: openjdk version "1.8.0_163"

### Example Application

https://github.com/benrhine/validateableInheritence

You can see the issue in EmployerValidationIntSpec, which uses Person and Employer objects

Contributor guide

Open the contributing guide

Research direction

Start with EmployerValidationIntSpec in the linked validateableInheritence example application and reproduce the null employees case. Trace the validation behavior for the minSize: 5 constraint, then add regression coverage showing that null fails while five employees passes, and run the relevant specification.

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
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.