Add clearConstraintsMapCache() public API to Validateable trait #15346
+85
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add a new static method
clearConstraintsMapCache()to theValidateabletrait that allows clearing the cached constraints map, forcing re-evaluation on next access.Motivation
The
Validateabletrait caches evaluated constraints in a private static fieldconstraintsMapInternal. During parallel test execution, constraints may be evaluated beforedoWithConfig()has registered shared constraints, causing test failures where shared constraint names (like'isProg') are not found.This new public API method enables proper test isolation by allowing tests to clear the constraint cache in setup/cleanup methods.
API Addition
Usage Example
Why This is a Feature (7.1)
Per the Grails versioning policy, adding a new public method to a trait is a backward-compatible feature addition that belongs in a MINOR release (7.1.x), not a PATCH release (7.0.x).
A companion change in PR #15335 (targeting 7.0.x) uses reflection to achieve the same test isolation without modifying the public API.
Files Changed
grails-validation/src/main/groovy/grails/validation/Validateable.groovy- Add newclearConstraintsMapCache()methodgrails-validation/src/test/groovy/grails/validation/ValidateableTraitSpec.groovy- Add test isolationgrails-validation/src/test/groovy/grails/validation/ValidateableTraitAdHocSpec.groovy- Add test isolationgrails-test-suite-web/src/test/groovy/org/grails/web/commandobjects/CommandObjectsSpec.groovy- Add test isolationgrails-test-suite-web/src/test/groovy/org/grails/web/commandobjects/CommandObjectNoDataSpec.groovy- Add test isolation