Skip to content

Apply the configured nullable default to properties copied with importFrom - #16474

Merged
jdaugherty merged 2 commits into
apache:8.0.xfrom
matrei:fix/import-from-default-nullable
Oct 2, 2026
Merged

jdaugherty merged 2 commits into
apache:8.0.xfrom
matrei:fix/import-from-default-nullable

Conversation

@matrei

@matrei matrei commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #16473

With grails.gorm.default.nullable: false, importFrom copied a property the source domain class leaves unconstrained as nullable: true. Command objects and domain classes that import constraints from such a domain class then accepted null where the domain class itself does not.

importFrom evaluated the source class with a new DefaultConstraintEvaluator, 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.newConstrainedPropertyBuilder passes the evaluator to the builder, and importFrom evaluates the source class with it. The existing ConstrainedPropertyBuilder constructor is kept, and falls back to the previous behaviour.
  • ImportFromSpec and DefaultConstraintEvaluatorSpec check, with the default set to false and to true, 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.
  • A new ImportFromDefaultNullableSpec for Hibernate 5 and Hibernate 7 checks the same through validate() and save(), with grails.gorm.default.nullable: false set in the datastore configuration.
  • The importFrom documentation 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".

…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

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.1522%. Comparing base (d13aa33) to head (3649ae0).
⚠️ Report is 45 commits behind head on 8.0.x.

Files with missing lines Patch % Lines
...onstraints/builder/ConstrainedPropertyBuilder.java 57.1429% 2 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                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     
Files with missing lines Coverage Δ
...n/constraints/eval/DefaultConstraintEvaluator.java 83.1081% <100.0000%> (ø)
...onstraints/builder/ConstrainedPropertyBuilder.java 65.0406% <57.1429%> (-1.3459%) ⬇️

... and 45 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

This comment has been minimized.

@jdaugherty

Copy link
Copy Markdown
Contributor
  1. No test covers the path from the issue. In a running app, a command object gets its evaluator from DefaultConstraintEvaluatorFactoryBean, which reads the setting from the application config. The PR's command-object test in ImportFromSpec calls DefaultValidatorRegistry.evaluate(...) instead, which reads the setting from the datastore settings. The fix itself is still tested, but not the config wiring a user actually hits. A small integration spec in grails-test-examples/gorm would cover it, since that app already sets nullable: false and has a ValidateableSpec. My probe there needed @Rollback.

  2. Doc wording is imprecise. This is in all three doc changes (sharingConstraints.adoc, Constraints.adoc, upgrading80x.adoc):

    • "leaves it unconstrained" is narrower than what happens. The default applies to any property that has no nullable constraint. In my probe, a property with only maxSize: 5 was also made required. Suggested wording: "a property for which the source declares no nullable constraint".
    • "unless grails.gorm.default.nullable is set to false" leaves out the wildcard form '*'(nullable: false), which also makes these properties required (and already did before this PR). In the upgrade guide, "unless you restore the required-by-default behaviour (below)" would cover both.

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.
@jdaugherty

Copy link
Copy Markdown
Contributor

I went ahead and addressed these issues so I could merge.

@jdaugherty
jdaugherty merged commit fc2565c into apache:8.0.x Oct 2, 2026
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

importFrom ignores grails.gorm.default.nullable: false for properties the source domain class leaves unconstrained

2 participants