Skip to content

FINERACT-2570: Defer webhook/hook event publication to after transaction commit in batch requests with enclosingTransaction=true#5719

Open
rhopman wants to merge 1 commit intoapache:developfrom
symbaglobal:FINERACT-2570-defer-webhook-event-publication
Open

FINERACT-2570: Defer webhook/hook event publication to after transaction commit in batch requests with enclosingTransaction=true#5719
rhopman wants to merge 1 commit intoapache:developfrom
symbaglobal:FINERACT-2570-defer-webhook-event-publication

Conversation

@rhopman
Copy link
Copy Markdown
Contributor

@rhopman rhopman commented Mar 30, 2026

When a batch request uses enclosingTransaction: true, Fineract fires hook events (webhooks) inside the database transaction, before the batch has fully committed. If a later request in the batch fails, the entire batch is rolled back, but the webhook for the earlier (now rolled-back) request has already been dispatched.

This causes downstream systems that rely on webhooks (e.g. SMS notifications) to act on events that never actually persisted.

Checklist

  • Write the commit message as per our guidelines
  • Acknowledge that we will not review PRs that are not passing the build ("green") - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
  • Create/update unit or integration tests for verifying the changes made.
  • Follow our coding conventions.
  • Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
  • This PR must not be a "code dump". Large changes can be made in a branch, with assistance. Ask for help on the developer mailing list.

…ion commit in batch requests with enclosingTransaction=true
@rhopman
Copy link
Copy Markdown
Contributor Author

rhopman commented Mar 30, 2026

Looks like the CI is failing because of an infrastructure issue. Can someone take a look and maybe re-run the checks?

2026-03-30T13:24:56.3956570Z FAILURE: Build failed with an exception.
2026-03-30T13:24:56.3956925Z 
2026-03-30T13:24:56.3957091Z * What went wrong:
2026-03-30T13:24:56.3957679Z Execution failed for task ':fineract-provider:jibDockerBuild'.
2026-03-30T13:24:56.3959077Z > com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException: 500 Internal Server Error
2026-03-30T13:24:56.3975585Z   GET https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/76/76eb174b37c3e263a212412822299b58d4098a7f96715f18c7eb6932c98b7efd/data?expires=1774880096&signature=OlfqELvYwlHJGEujrzRogqXsb8U%3D&version=3
2026-03-30T13:24:56.3977588Z   <html>
2026-03-30T13:24:56.3978070Z   <head><title>500 Internal Server Error</title></head>
2026-03-30T13:24:56.3978911Z   <body>
2026-03-30T13:24:56.3979353Z   <center><h1>500 Internal Server Error</h1></center>
2026-03-30T13:24:56.3979917Z   <hr><center>cloudflare</center>
2026-03-30T13:24:56.3980387Z   </body>
2026-03-30T13:24:56.3980747Z   </html>

long commandId = 1L;
JsonCommand jsonCommand = Mockito.mock(JsonCommand.class);
when(jsonCommand.commandId()).thenReturn(commandId);
when(jsonCommand.json()).thenReturn(null); // publishHookEvent exits early when json is null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the intent here returning null saves us from having to mock a bunch of stuff for publishHookEvent.

But right now, the test doesn't have any assertions; it just passes because nothing breaks. At the very least, we can drop in an assertFalse(TransactionSynchronizationManager.isSynchronizationActive()) to prove no sync was registered.

Also, the test name mentions "PublishedImmediately", but returning null skips publication altogether. Might be worth either renaming the test to fit what's actually happening or adding the mocks to verify the immediate publication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants