matrei opened a new pull request, #16390:
URL: https://github.com/apache/grails-core/pull/16390
## Summary
When `save()` fails validation, the Hibernate 5 `handleValidationError` is
meant to mark the invalid instance and its to-one associations read-only, so a
later flush in the same session cannot write them. The association check was
written as
```groovy
if (association instanceof ToOne && !association instanceof Embedded) {
```
which Groovy parses as `(!association) instanceof Embedded`. That is always
false, so only the instance itself was ever marked read-only. Unsaved changes
on an associated object could still be flushed after the failed save.
The Groovy 6 upgrade experiment (#16387) found this: Groovy 6 rejects `!x
instanceof T`. The fix does not depend on Groovy 6, so it is submitted
separately here.
## Changes
- `AbstractHibernateGormInstanceApi.handleValidationError` uses
`!(association instanceof Embedded)`, so non-embedded to-one associations that
are already loaded are marked read-only as intended. Associations that are
still unloaded proxies are left alone, as before.
## Testing
New `ValidationErrorToOneReadOnlySpec` in `grails-data-hibernate5-core`:
- A saved author gets an unsaved rename, then a book referencing it fails
validation. The author is read-only in the session, and after an explicit flush
and reload its name is unchanged. This feature fails without the fix.
- When the author is an unloaded proxy, the failed save does not load it.
`:grails-data-hibernate5-core:test` passes (601 tests, 0 failures) and so
does `./gradlew codeStyle`.
## Follow-up
On `8.0.x` the Hibernate 5 copy is already fixed, so the merge-up only
brings this spec along. The same check in the Hibernate 7
`HibernateGormInstanceApi` needs its own PR against `8.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]