Skip to content

Per-Handler Transaction Mode Override Ignored with Storage Side Effects #2319

@adrienmollat-a11y

Description

@adrienmollat-a11y

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.

EagerBeginTransactionAsync() at the beginning of the Handler

LightWeight → no BeginTransactionAsync()

Desktop:

  • OS: iOS
  • Browser: chrome
  • Version: 5.19.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions