apache / apache/grails-core

Shared constraint validation seems to fail in HibernateSpec unit tests on non-domain Validateable object with Grails 3.3.10

Open
#11,385 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

Related to issue #10782

- [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 non domain object with Validateable trait
2. Create a default constraint in application.groovy
3. try and use that shared constraint from the non-domain object.

### Expected Behaviour

The shared constraint should be used

### Actual Behaviour

The shared constraint is not found, a ValidationConfigurationException is thrown with the message
Property [...] references shared constraint [...:null], which doesn't exist!
at org.grails.datastore.gorm.validation.constraints.eval.DefaultConstraintEvaluator.applySharedConstraints(DefaultConstraintEvaluator.java:201)
at org.grails.datastore.gorm.validation.constraints.eval.DefaultConstraintEvaluator.evaluate(DefaultConstraintEvaluator.java:176)
at grails.validation.Validateable$Trait$Helper.validate(Validateable.groovy:161)
at grails.validation.Validateable$Trait$Helper.validate(Validateable.groovy:93)

### Environment Information

- **Operating System**: Windows
- **Grails Version:** 3.3.10
- **JDK Version:** 1.8
- **Container Version (If Applicable):** none

### Example Application

git@github.com:tircnf/sharedValidatable.git

The example has one domain object marked with Validateable, one integration test, and two unit tests. (one which is a HibernateSpec).

The custom validator should always cause validation to fail, with the error code 'junk'.

The custom validator is applied to the integration test (ticket #10782 ), but doesn't get applied in unit tests.

The unit tests pass for Domain object, just not for non-domain objects.

Contributor guide

Open the contributing guide

Research direction

Start with DefaultConstraintEvaluator.applySharedConstraints and the Validateable.groovy validate path shown in the stacktrace. Reproduce the issue with the sharedValidatable example application, comparing its HibernateSpec tests for domain and non-domain Validateable objects. Done means the shared constraint and custom validator apply in the non-domain unit test, producing the expected 'junk' error code.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend, testing
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.