Hello community.
I have seen previous mentions like
https://success.outsystems.com/documentation/11/reference/outsystems_language/data/database_reference/handling_transactions/ and https://www.outsystems.com/forums/discussion/38493/commit-transaction-action-when-is-it-needed-why/
stating the end node implicitly commits transactions.
My question is this: if I have a request that spans multiple server actions and more than one of these actions writes to the database when is the transaction committed?
ie is the transaction commit at the end node of the first action that writes data?
and then there is another transaction for the second write?
or can I rollback multiple writes in multiple actions with one exception rollback?
thank you,
Andy
Hi @Andy Cody
Hope you are well,
"The commit happen when the top most end node reaches."
By default there are exception handlers if you don't define any, in which there is abort transaction which roll back everything.
For your use case.
Request
action 1 calls
action2 write1 end2
action3 write 2 end3 (IF ERROR)
end1 - (CATCHES EXCEPTION - ROLL BACK EVERYTHING)
end request
If your action3 had any exception handler and set to abort transaction, it will abort complete transaction happen so far, which includes actions2 as well.
Let's go in bit details.
action 1 calls - fine
action2 write1 end2 - fine
action3 write 2 (IF ERROR)
Raise Exception
If action 3 Has Exception handler
Abort the transaction
END (it's end for entire transaction)
If action 3 Not has exception handler
Move the exception to action1
If action 1 Has exception handler
If action 1 Not has exception handler
Move the exception to Global Handler (It abort the transaction)
end1
Once Exception occur it follows the path of handler and ends there, rolling back everything so far.
Hope this will help you!
wow @Drishti Menghani what a great answer. thanks very much.
Lovely reminder of how smart and helpful the community can be.
Mention not!! always there to help. : )
hi @Andy Cody
You can check this links:
https://www.outsystems.com/forums/discussion/35738/transactions-in-sql-server-database/
https://www.outsystems.com/forums/discussion/2830/transactions-in-the-outsystems-platform/
I hope this helps
Thanks
Hi Andy,
By default in OutSystems, the End node automatically commits any open transaction when it’s reached. That means if you execute several Server Actions that write to the database, and you never call CommitTransaction explicitly, the platform will commit all those changes once flow reaches the End node.
If you need control and want each Server Action’s database changes to be committed immediately after it runs, you can insert a CommitTransaction action after each Server Action.
If you never invoke CommitTransaction explicitly and one of your Server Actions throws an uncaught exception, the entire transaction is rolled back automatically. In that case, all database changes made within that transaction are reverted.
thanks @Rupesh Patil & @Mihai Melencu for your replies.
Sorry Mihai, to clarify when you say
"the platform will commit all those changes once flow reaches the End node"
is that the final end node of the final server action of the entire request or
is it the immediate end node of the action the database write is in?
eg
action3 write 2 end3
if I hit an error in action3 and rollback,
is write1 rolled back or has it been committed at end2
thanks again
Andy.