Repository navigation
Apply the configured nullable default to properties copied with importFrom - #16474
Conversation
…tFrom importFrom evaluated the source class with a new evaluator that always used the framework's nullable default, so with grails.gorm.default.nullable set to false, a property the source domain class leaves unconstrained was imported as nullable. The source class is now evaluated with the evaluator that is evaluating the importing class.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16474 +/- ##
==================================================
+ Coverage 58.9274% 59.1522% +0.2247%
- Complexity 24440 24606 +166
==================================================
Files 2174 2170 -4
Lines 107366 107614 +248
Branches 19557 19606 +49
==================================================
+ Hits 63268 63656 +388
+ Misses 35235 35104 -131
+ Partials 8863 8854 -9
🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
|
Adds an integration spec to the gorm example app, which sets grails.gorm.default.nullable to false, so a Validateable command object importing from a domain class is covered through the evaluator the application context provides rather than DefaultValidatorRegistry. The docs now say the default applies to any property the source class declares no nullable constraint for, and mention the '*'(nullable: false) global constraint alongside grails.gorm.default.nullable.
|
I went ahead and addressed these issues so I could merge. |
Fixes #16473
With
grails.gorm.default.nullable: false,importFromcopied a property the source domain class leaves unconstrained asnullable: true. Command objects and domain classes that import constraints from such a domain class then acceptednullwhere the domain class itself does not.importFromevaluated the source class with a newDefaultConstraintEvaluator, which always uses the framework's nullable default and so ignored the configured one. It now uses the evaluator that is evaluating the importing class, so the source class gets the same defaults.Changes
DefaultConstraintEvaluator.newConstrainedPropertyBuilderpasses the evaluator to the builder, andimportFromevaluates the source class with it. The existingConstrainedPropertyBuilderconstructor is kept, and falls back to the previous behaviour.ImportFromSpecandDefaultConstraintEvaluatorSpeccheck, with the default set tofalseand totrue, that a property the source leaves unconstrained follows the configured default, both for a domain class and for a command object, and that explicit constraints are imported unchanged.ImportFromDefaultNullableSpecfor Hibernate 5 and Hibernate 7 checks the same throughvalidate()andsave(), withgrails.gorm.default.nullable: falseset in the datastore configuration.importFromdocumentation in the validation guide and the constraints reference says which nullable default imported properties get. The 8.0 upgrade guide now notes that this is an exception to "command objects are unaffected".