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

   ## Description
   
   This is a follow-up to the 8.0.x port of #16515 in the merge-up 993c048ea63, 
which restricts lookups by id to the current tenant with `DISCRIMINATOR` 
multi-tenancy.
   
   ### Lookups by id through `withTenant` inside `withoutId`
   
   Inside `Tenants.withoutId`, a query through `withTenant(tenantId)` is 
restricted to that tenant. A lookup by id through it was not, on GORM for 
MongoDB and GORM's in-memory datastore, and neither was `getAll` on GORM for 
Neo4j:
   
   ```groovy
   Tenants.withoutId {
       Note.withTenant('other').findById(id) // null for another tenant's 
instance
       Note.withTenant('other').get(id)      // found it
   }
   ```
   
   `GormStaticApi` decided whether a lookup by id goes through a query before 
`execute`, where `withoutId` was still in effect. The API binds the tenant of a 
qualifier only while the session callback runs. The decision is now made inside 
the callback, for the session's datastore, as the multi-tenant event listener 
makes it, so the tenant that `withTenant` binds applies. GORM for Neo4j already 
restricted `get` and `exists` there, because its lookup by key runs a query.
   
   To call them from the session callbacks, `isRetrievedByQuery`, 
`retrieveAllByQuery` and `proxyByQuery` are now protected and take the session, 
as `findAllByKeys` and the other helpers already did.
   
   ### `getAll` with an iterable of ids
   
   `getAll(Iterable)` passes its ids to `getAll(Serializable...)` again, as on 
7.x. Since #16066 it looked them up itself, so a subclass that overrides 
`getAll(Serializable...)` didn't handle a list of ids. GORM for Hibernate 7's 
static API is one: `getAll` with a list of ids went through its session, or in 
`DISCRIMINATOR` mode through a GORM query, rather than through its own 
`getAll`. The results are the same.
   
   ### Documentation
   
   - The partitioned multi-tenancy section of the GORM for Neo4j guide says 
that lookups by id are restricted to the current tenant, as the GORM for 
MongoDB guide does.
   - Upgrade note 88 said that inside `withoutId` a lookup by id is not 
restricted to a tenant. That holds for GORM for MongoDB and GORM's in-memory 
datastore. With GORM for Neo4j, `get` there finds only the instances of the 
tenant `default`, as its queries do. That is unchanged, so the note now says 
that lookups by id work as before inside `withoutId`.
   
   ### Tests
   
   - `PartitionedLookupByIdSpec` (`grails-datamapping-core-test`) and 
`MongoLookupByIdMultiTenancySpec` (`grails-data-mongodb-core`) have a new 
feature for `findById`, `get`, `exists` and `getAll` through `withTenant` 
inside `withoutId`. It fails without the change. The label `the tenant id 
DEFAULT` is now `the tenant id default`, the tenant id these features use on 
8.0.x.
   - `LookupByIdMultiTenancySpec` (`grails-data-neo4j-core`, new) covers 
lookups by id with GORM for Neo4j, as the MongoDB spec does: 10 features, 
without composite and numeric ids, and without the ones that look an instance 
up inside `withoutId`. Only the one for `withTenant` inside `withoutId` fails 
without the change, for `getAll`. The others pass with the port in 993c048ea63 
as well.
   - `GormStaticApiSpec` has two new features. One checks that 
`getAll(Iterable)` passes its ids to `getAll(Serializable...)` and fails 
without the change. The other covers lookups by id of a multi-tenant entity in 
`DISCRIMINATOR` mode on `GormStaticApi` itself.
   
   These pass with the change:
   
   - all tests of `grails-datamapping-core`, `grails-datamapping-core-test`, 
`grails-data-simple`, `grails-datastore-web`, `grails-data-hibernate5-core`, 
`grails-data-hibernate7-core`, `grails-data-mongodb-core` and 
`grails-data-neo4j-core`;
   - `codeStyle` for `grails-datamapping-core`, `grails-data-mongodb-core` and 
`grails-data-neo4j-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]

Reply via email to