matrei opened a new issue, #16473:
URL: https://github.com/apache/grails-core/issues/16473
## Summary
With `grails.gorm.default.nullable: false`, a domain class property without
a `nullable` constraint is required. When another class copies the domain
class's constraints with `importFrom`, that property is copied as `nullable:
true`, so the importing class accepts `null` where the domain class does not.
This applies both to command objects and to domain classes that use
`importFrom`.
On 7.0.x, these properties were imported as required. Setting
`grails.gorm.default.nullable: false` is the documented way to keep the 7.x
behaviour in 8.0, but it does not reach `importFrom`.
## Reproduce
`application.yml`:
```yaml
grails:
gorm:
default:
nullable: false
```
```groovy
@Entity
class User {
String name
String nickname
static constraints = {
nickname(nullable: true)
}
}
class UserCommand implements Validateable {
String name
String nickname
static constraints = {
importFrom(User)
}
}
```
```groovy
assert !new User().validate() // name is required, as configured
assert new UserCommand().validate() // passes: name was imported as
nullable
```
The same happens for a domain class that uses `importFrom(User)`.
**Expected:** `UserCommand.name` is required, like `User.name`.
**Actual:** `UserCommand.name` is nullable.
## Cause
`ConstrainedPropertyBuilder.handleImportFrom` evaluates the source class
with a new `DefaultConstraintEvaluator`, built with the 3-argument constructor.
That constructor sets the nullable default for persistent properties to `true`
and ignores the configured setting, so every property the source leaves
unconstrained gets an explicit `nullable: true`, which `importFrom` then copies
to the importing class.
## Suggested fix
Evaluate the `importFrom` source with the evaluator that is evaluating the
importing class, so the source gets the same nullable default.
## Environment
Grails 8.0.0-SNAPSHOT (`8.0.x`). Introduced together with the configurable
nullable default; not present on 7.0.x.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]