Describe the bug
The Per-Handler Transaction Mode override attribute does not behave consistently and appears to be ignored in some scenarios.
Based on the documentation:Transactional Middleware | Wolverine the attribute should override the global transaction mode (Eager / LightWeight). However, during testing, this is not always the case.
The issue seems to occur when handlers include DB updates with the wolverine Storage Side effect: Isolating Side Effects from Handlers | Wolverine
(Storage.Insert(), Storage.Update()) or with Saga creation in Saga Start Handler.
To Reproduce
Configure a global transaction mode (Eager or Lightweight):
public void Configure(WolverineOptions options)
{
...
options.UseEntityFrameworkCoreTransactions(); // Eager mode by default
...
}
Add a handler with a Per-Handler override attribute (Here Lightweight as we chose Eager in the global configuration), and a wolverine Storage Side effect (in my case, Insert or Update):
[Transactional(Mode = TransactionMiddlewareMode.Lightweight)]
public static (Update<DbTable1>, Insert<DbTable2>) Handle(
MessageType msg,
...
) {
...
return (Storage.Update(elem1), Storage.Insert<DbTable2>(elem2))
}
Check the generated code and see:
...
// This should not be here in LightWeight Mode
if (ctx.Database.CurrentTransaction == null)
{
await ctx.Database.BeginTransactionAsync(cancellation).ConfigureAwait(false);
}
...
Expected behavior
The Per-Handler attribute should always override the global configuration.
Eager → BeginTransactionAsync() at the beginning of the Handler
LightWeight → no BeginTransactionAsync()
Desktop:
- OS: iOS
- Browser: chrome
- Version: 5.19.1
Describe the bug
The Per-Handler Transaction Mode override attribute does not behave consistently and appears to be ignored in some scenarios.
Based on the documentation:Transactional Middleware | Wolverine the attribute should override the global transaction mode (
Eager/LightWeight). However, during testing, this is not always the case.The issue seems to occur when handlers include DB updates with the wolverine Storage Side effect: Isolating Side Effects from Handlers | Wolverine
(
Storage.Insert(),Storage.Update()) or with Saga creation in Saga Start Handler.To Reproduce
Configure a global transaction mode (
EagerorLightweight):Add a handler with a Per-Handler override attribute (Here Lightweight as we chose Eager in the global configuration), and a wolverine Storage Side effect (in my case, Insert or Update):
Check the generated code and see:
Expected behavior
The Per-Handler attribute should always override the global configuration.
Eager→BeginTransactionAsync()at the beginning of the HandlerLightWeight→ noBeginTransactionAsync()Desktop: