Repository navigation
Description
What actually happened?
registerSamples calls registerSamplesFromMetadata as a self-invocation, so the Spring AOP annotations on the callee never take effect:
// SampleRegistrationServiceV2.java:103-105
return registerSamplesFromMetadata(metadata, projectId, experimentReference);// SampleRegistrationServiceV2.java:108-114
@PreAuthorize("...")
@Async
@Transactional
public CompletableFuture<Void> registerSamplesFromMetadata(...)Because the call goes through this rather than through the Spring proxy, @Async, @Transactional and @PreAuthorize on registerSamplesFromMetadata are bypassed on this path. @Async returns a plain CompletableFuture.completedFuture(null) rather than being scheduled, and the method body runs in the caller's thread and transaction.
Current practical impact is limited and this is filed mainly as code health, not as a live defect: the outer registerSamples (:73-75) already carries @Async, @Transactional and an equivalent @PreAuthorize, so the registration still runs asynchronously, transactionally and with the same permission check. Nothing is broken today.
The risk is that the annotations on the callee are actively misleading:
- A reader reasonably assumes
registerSamplesFromMetadataestablishes its own transaction boundary. It does not — it inherits the caller's. That is exactly why the compensatingdeleteSamplescall inside it cannot work (see [Bug] Sample registration compensation cannot work: doomed transaction, empty list, or never reached #1698): aREQUIRES_NEWboundary cannot be introduced from within a self-invoked method. - If a future caller (a new API endpoint, a test, another service) invokes
registerSamplesFromMetadatathrough the proxy, behaviour changes silently: no transaction would enclose the workflow if called from a non-transactional context, and@Asyncwould suddenly apply. - The Spock test calls the method directly on an instance (
SampleRegistrationServiceV2Spec.groovy:57), so the annotations are never exercised by tests at all.
What did you expect to happen?
One of:
- Remove the redundant annotations from
registerSamplesFromMetadataand make the single transaction boundary explicit and documented (it belongs on the entry point), or - Keep a real boundary on the callee and call it through the proxy (
selfProxy/@Lazy self, the pattern already used bySampleRepositoryImpl(:48-54) andDeletionService(:30, 42, 51)).
Option 2 is a prerequisite if compensation is to be implemented as a separate transaction anywhere in this flow. This is closely tied to #1698 and #1694, and should be decided together with them rather than fixed in isolation.
Steps to reproduce
- Set a breakpoint in
registerSamplesFromMetadataand compareThread.currentThread().getName()with the caller's — it is identical, showing no async dispatch for the inner call. - Alternatively, log
TransactionSynchronizationManager.isActualTransactionActive()inside both methods; the inner call adds no new boundary.
Affected application area
Sample Management
Browser(s) where the problem occurs
Not browser-specific / backend issue
Additional context
- Same self-invocation pattern exists in
MeasurementService(registerMeasurementNGS→performRegistrationNGS) and inRawDataSyncService, which already solves it explicitly with a@Lazyself reference (:59-71) and documents why. @Asyncon the tested method means the Spock spec exercises the object, not the proxied bean — worth noting for anyone trying to test the async path.- Severity is deliberately filed as low: no user-visible defect today, but it blocks the compensation fix and misleads readers.
- Related: [Bug] Sample registration compensation cannot work: doomed transaction, empty list, or never reached #1698, [Spike] Decide how sample registration stays consistent between MariaDB and openBIS #1694.
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity