apache / apache/grails-core

Grails 3.2.9 validate() method of domain object returns False when it used to return True on Grails 3.1.12

Open
#14,615 8 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] 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

1 - Create a Domain class called Parent with a property Child.
2 - Create a Domain class called Child with dummy string as property and a back-reference as static belongsTo = [ parent : Parent ];
3 - Set a constraint on Child to parent( nullable: false ).
4 - Use databinding on parent to populated the child's dummy string.
5 - Call validate() method on parent - it will return TRUE on grails 3.1.12 and FALSE on 3.2.9.

### Expected Behaviour

The call to validate() method on parent should always return TRUE for backwards compatibility and not breaking existing code.

### Actual Behaviour

The call to validate() method on parent returns different values depending on the Grails version running.

### Environment Information

- **Operating System**: Windows 10 64 bits
- **Grails Version:** 3.1.12 and 3.2.9 confirmed for inconsistency.
- **JDK Version:** jdk1.8.0_121
- **Container Version (If Applicable):** Tomcat8

### Example Application

Example running with Grails 3.1.12 https://github.com/rafajaw/grails-validate-issue-a
Example running with Grails 3.2.9 https://github.com/rafajaw/grails-validate-issue-b

### Additional notes

In further investigation we can see that validate() method fails in Grails 3.2.9 because the constraint "parent( nullable: false )" wasn't met in the child object.

However, if we call parent.save() then the back-reference from child to parent gets populated properly and the validate() method begins to return TRUE even for Grails 3.2.9. Which is not always the use-case, in some use-cases we want to explicitly call validate on the object without saving it.

Contributor guide

Open the contributing guide

Research direction

Start with the two example applications linked in the issue and reproduce the Parent/Child databinding and validate() behavior on Grails 3.1.12 and 3.2.9. Trace domain validation and the Child parent constraint to identify the version difference. Done means validating the populated parent without saving it returns the expected result consistently.

Written by the indexing model from the issue text.

Assessment

Domain
backend
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.