matrei opened a new pull request, #16509: URL: https://github.com/apache/grails-core/pull/16509
## Description In discriminator multi-tenancy, GORM's `MultiTenantEventListener` sets the current tenant id on an instance before it is validated, inserted or updated. When there is no current tenant, the tenant resolver throws a `TenantNotFoundException`. Since #16066, the listener resolves the tenant inside the `try` block that turns a failure to set the property into a `TenantException`. A save without a tenant then fails with a misleading message: ``` TenantException: Could not assigned tenant id [null] to property [tenantId], probably due to a type mismatch. You should return a type from the tenant resolver that matches the property type of the tenant id! ``` It used to throw the `TenantNotFoundException`, and a query without a tenant still does. 7.0.x is not affected. The listener now rethrows a `TenantNotFoundException` unchanged. A failure to set the tenant id property is still wrapped as before. This affects the datastores that use GORM's listener, such as MongoDB and the simple datastore. GORM for Hibernate 5 and 7 have their own listener. ### Tests - `MultiTenantEventListenerSpec`: a new feature checks that a `TenantNotFoundException` from the tenant resolver is rethrown unwrapped, and that no tenant id is set. - `PartitionMultiTenancySpec` (simple datastore): a new feature checks through the public API that saving without a tenant throws `TenantNotFoundException`. Both new features fail without the change. All multi-tenancy specs of `grails-datamapping-core` and `grails-datamapping-core-test` pass, and so do `checkstyleMain` and `codenarcTest` of `grails-datamapping-core`. -- 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]
