You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example that reproduces the problem uploaded to Github
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<Employee> 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
We should check to see if this is a recently introduced problem or if this has been this way for a long time. If it is not related to a recently introduced problem then we probably should be careful about which release we put the change in because it is going to be a breaking change for folks who are expecting the previous behavior. Similar issues have been discussed before with respect to combinations of things like blank: false and nullable: true. We should also add some clarity to the constraint docs around expected behavior for these problematic combinations.
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
If you call
.validate()
on an thisEmployer child = new Employer(name: 'TEST', company: 'TEST')
this will validate as true even when employees is null.If you call
.validate()
on an thisEmployer 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 thisEmployer 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
Example Application
https://github.com/benrhine/validateableInheritence
You can see the issue in EmployerValidationIntSpec, which uses Person and Employer objects
The text was updated successfully, but these errors were encountered: