Skip to content

minSize constraint validates is true when null value is present #14575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 of 4 tasks
benrhine opened this issue Apr 13, 2018 · 1 comment
Open
3 of 4 tasks

minSize constraint validates is true when null value is present #14575

benrhine opened this issue Apr 13, 2018 · 1 comment

Comments

@benrhine
Copy link
Contributor

benrhine commented Apr 13, 2018

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • 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

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

@jeffscottbrown
Copy link
Contributor

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.

@jdaugherty jdaugherty transferred this issue from apache/grails-data-mapping Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants