Shared constraints not taking into account
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Expected Behavior
Shared constraints need to be applied when added from grails-app/conf/runtime.groovy.
### Actual Behaviour
Shared constraints are not taking into account when creating an instance of a domain class. We can even define a domain class field with a shared constraint that does not even exist and the application does not complain about it.
### Steps To Reproduce
I have created a repo in github at https://github.com/frangarcia/shared-constraints-issue. I have just created the file grails-app/conf/runtime following the instructions at https://docs.grails.org/latest/ref/Constraints/Usage.html and added a shared constraint:
```
grails.gorm.default.constraints = {
basicString(nullable: true, size: 1..5)
}
```
at the same time, I have created a new domain class
```
package net.frangarcia
class Account {
String name
static constraints = {
name(shared:'basicString')
}
}
```
and then, tried to create and save a new instance of account with a name with more than 5 characters and it is still saved. I have done this in Bootstrap.groovy:
package shared.constraints.issue
```
import net.frangarcia.Account
class BootStrap {
def init = { servletContext ->
Account account = new Account(name:"my account name").save()
println "*"*100
println "account id = ${account.id}"
println "*"*100
}
def destroy = {
}
}
```
If you start the application with ./gradlew bootRun, you will see the account has been created.
### Environment Information
- Operating system: Mac OS 10.15.7
- JDK: openjdk version "1.8.0_332"
### Example Application
https://github.com/frangarcia/shared-constraints-issue
### Version
5.2.0
Contributor guide
Research direction
Start with the shared constraint configuration in grails-app/conf/runtime.groovy and the Account constraints in the example application. Run ./gradlew bootRun and reproduce the Bootstrap.groovy save with a name longer than five characters. Done means the shared size constraint is applied and the invalid Account is rejected or reports validation errors.
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
- 35/100