Repository navigation
Conversation
…enant transaction. ### Changes - Removed the existing guard’s `flush: true` bypass. - Preserved its method signature. - Extended existing in-memory and MongoDB tests for flushed writes and already-bound sessions. - Corrected the exception message, 9.0 upgrade guide, and matching upgrade guidance. ### Validation All affected suites passed with zero failures: - Datamapping core: 2,694 tests - Datamapping CLI: 213 tests - Datamapping TCK: 765 tests - MongoDB core: 1,329 tests
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A flushed save inside a failed tenant block is refused. A save of a plain class with no tenant transaction is now refused too.
…tenant datastore lookup: - Skip the write guard before tenant lookup when no transaction is active. - Preserve rejection of unsafe writes during an active tenant transaction, including `flush: true`. - Add regression coverage for unregistered tenant IDs and bound sessions in the in-memory and MongoDB suites. - Clarify the upgrade guide.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A save of a plain class with no tenant transaction still throws when another transaction is active.
… unrelated active transactions. - Plain-class writes still reach the default datastore with an unregistered tenant ID bound. - Unsafe writes during a real tenant transaction remain rejected, including `flush: true`. - Added regression tests and updated the upgrade guide.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A save inside a tenant transaction is allowed when that transaction does not use synchronization.
…that transaction does not use synchronization: - Removed the thread-level transaction flag shortcut; active tenant transactions are now detected through session holders even when synchronization is disabled. - Added regression coverage and expanded the database/schema tenancy tests. - Updated the upgrade guide.
jamesfredley
left a comment
There was a problem hiding this comment.
The items this review found have been addressed. A save inside a tenant transaction is refused even when that transaction does not use synchronization, and a save with no tenant transaction is not refused because another transaction is active.
sbglasius
left a comment
There was a problem hiding this comment.
This is an AI assisted review
Looks good. Two small suggestions:
| * @param flush Whether the write is flushed at once | ||
| * @param flush Whether the write is flushed at once; this does not exempt it from requiring its own transaction | ||
| */ | ||
| protected void requireTransactionForWrite(boolean flush) { |
There was a problem hiding this comment.
flush is no longer used. Since 9.0 can change this API, consider dropping the parameter from this method and its six callers.
| return | ||
| } | ||
| boolean tenantTransactionActive = false | ||
| for (Map.Entry<Object, Object> entry : TransactionSynchronizationManager.getResourceMap().entrySet()) { |
There was a problem hiding this comment.
After the tenantConnection == null check, this loop looks the same as isTransactionActive(multiTenantDatastore.getDatastoreForTenantId(tenantId)). Resource binding doesn't depend on synchronization, and the datastore identity check already implies the connection check. Can it be simplified, or is there a case it covers that I'm missing?
Removed the unused `flush` parameter and its Javadoc entry. - Updated all six callers to use `requireTransactionForWrite()`. - Expanded regression coverage for all affected write operations, including bulk iterable overloads. - Left flushing and transaction-detection behavior unchanged. Replaced the resource-map loop with a direct `isTransactionActive(...)` check on the tenant datastore. - Retained the unregistered-tenant guard. - Updated the Javadoc and expanded tests for registered tenants and inactive tenant sessions, including unrelated transactions and disabled synchronization.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A flushed save of a class mapped only to a named connection throws when a tenant id is bound.
| } | ||
| Datastore tenantDatastore = multiTenantDatastore.getDatastoreForTenantId(tenantId) | ||
| if (tenantDatastore.is(ds) || !isTransactionActive(tenantDatastore)) { | ||
| ConnectionSource tenantConnection = multiTenantDatastore.connectionSources.getConnectionSource(tenantId.toString()) |
There was a problem hiding this comment.
A class is mapped only to a named connection, and it is not multi-tenant. A tenant id is bound, and the class is saved with a flush. That save should go through. It throws, because the named connection is treated as a tenant datastore that has no transaction. Allow the save.
…ferent tenant’s datastore. - Added regression coverage for matching, different, and unregistered tenant IDs. - Updated the upgrade guide.
Description
Fixes #17031
Root Cause
flush: trueinAbstractGormApi.requireTransactionForWriteincorrectly bypassed the transaction-safety check.In DATABASE or SCHEMA multi-tenancy, a plain domain class—one that does not implement
MultiTenant—writes to its own datastore, typically the default database. A transaction running for a tenant belongs to a different datastore and cannot roll back that plain class’s writes.The guard in
AbstractGormApi.requireTransactionForWritewas intended to reject those writes unless the plain class had a transaction in its own datastore. However, it returned immediately when flushing was requested:Consequently,
save(flush: true)could write the row immediately outside the tenant’s transaction. When the tenant transaction subsequently failed, the row remained.Changes
flush: truebypass.Validation
All affected suites passed with zero failures:
Assisted with GPT 6 Sol
Contributor Checklist
Please review the following checklist before submitting your pull request. Pull requests that do not meet these requirements may be closed without review.
Issue and Scope
7.0.x): Bug fixes only. No new features or API changes.7.1.x): New features are welcome, but breaking existing APIs must be avoided.8.0.x): Reserved for major changes. Breaking API changes are permitted.Code Quality
./gradlew build --rerun-tasks../gradlew codeStyleand resolved any violations. See Code Style for details.Licensing and Attribution
Documentation