-
Notifications
You must be signed in to change notification settings - Fork 199
Description
GormValidateable has a property skipValidate that is trying to skip calling validate multiple times when an entity is saved and then later flushed.
However, it has the potential to cause validations to be skipped under some scenarios. It's also completely ignored for explicit calls to validate() without a list of properties, which seems inconsistent.
The attached project's AuthorSpec test does the following:
- Create a new valid Author and call save but don't flush
- Update the
nameattribute on the Author instance to an invalid state - Call
validate(['name'])to re-validate the author instance - Validation should fail, however step 1 left the Author with
skipValidate = trueso validation is skipped instead and the validate returnstrue
If you call validate without any properties, the validation will fail as expected, which seems like a weird side effect as well.
The problem is that this finally block:
Incorrectly restores the skipValidate based on the shouldFlush flag, which leaves the non-flushed object in this state.
It almost seems like it should just restore the skipValidate to false after everything is finished instead of tying it to !shouldFlush.
- **GORM Version: 6.1.10.RELEASE
- **Grails Version (if using Grails): 3.3.8
- **JDK Version: 1.8.0_111