matrei opened a new pull request, #16511:
URL: https://github.com/apache/grails-core/pull/16511

   ## Description
   
   In discriminator multi-tenancy, GORM's `MultiTenantEventListener` sets the 
tenant id of an instance when it is validated, inserted or updated. On 7.0.x 
the current tenant decides it. A tenant id already set on the instance is kept 
only when there is no current tenant, that is, when the current id is the 
default connection source.
   
   Since #16066, the listener on 8.0.x keeps any tenant id already set on the 
instance. An instance whose tenant id names another tenant is then saved under 
that tenant instead of the current one, and an update can move an instance to 
another tenant.
   
   The listener now decides as on 7.0.x again: the current tenant wins, and an 
already-set tenant id is kept only when the current id is the default 
connection source. Coercing that default to `0L` for a numeric tenant id is 
unchanged.
   
   This applies to the datastores that use GORM's listener, such as MongoDB and 
the simple datastore. GORM for Hibernate 5 and 7 have their own listener, which 
already lets the current tenant win.
   
   The behaviour is that of 7.0.x, so no documentation changes.
   
   ### Tests
   
   - `MultiTenantEventListenerSpec`:
     - the feature that asserted that an already-set tenant id wins is replaced 
by one checking that the current tenant id replaces it, for a validation, an 
insert and an update
     - a new feature checks that an already-set tenant id is kept when the 
current id is the default connection source
   - `PartitionMultiTenancySpec` (simple datastore): a new feature saves a book 
whose tenant id names another tenant, and checks that it is saved under the 
current tenant and is not visible to the other one, and that changing the 
tenant id of a saved book does not move it.
   
   The new features, apart from the one for the default connection source, fail 
without the change. These pass with it:
   - all tests of `grails-datamapping-core`, `grails-datamapping-core-test` and 
`grails-data-simple`
   - the multi-tenancy specs of `grails-data-mongodb-core`
   - `checkstyleMain` and `codenarcTest` of `grails-datamapping-core`
   
   #16509 changes the exception handling of the same method, so whichever is 
merged second may need a small rebase.


-- 
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]

Reply via email to