In the above scenario, If any error occurs in ListAll server action, ListAppend will execute or how rollback works here?
Same way If any error occurs in 2nd server action, what about the first server action commit or rollback?
My intension to learn how rollback works in server actions? Can someone help
Note:
ListAll and ListAppend are dummy server actions which i created. Please treat them as any other server actions or Service Actions
Hi Mahesh,
When a request is started until the request successfully finished no automatic commit is done by OutSystems, only if you explicitly execute a CommitTranstion action database changes are commited. So If the ListAll succesfully ends and it did database changes that you DID NOT explicitly commit, and then the ListAppend gets an exception, the default behavior is that the database transaction is rolled back.
Again your server actions names do not suggest any database changes take place, for me that is confusing, I would name them to reflect more what they do.
Also you can easily test all this by just coding the logic, and implement a statement that causes an exception like divide by zero, and see the effect on your entity data.
Regards,
Daniel
I believe if an error occurs in either server action 1(ListALL) or 2(ListAppend), complete transaction rollback. Is it true?
It all depends on how you do your exception handling.
Without any build in exception handling, if a request fails due to an unexpected error a database rollback will be performed. However in your example that would have no effect as I see no logic that does database updates. A server action does not automatically a commit, a commit of all your database changes is performed after the request is completed. So ListAll and ListAppend do not perform commit/rollback. If they fail then your server actions fails, as it has no exception handler, the exception will bubble up in the call stack, ultimately reaching a global exception handler.
For more information about exception handling please read the OutSystems documentation on Exception Handling Mechanism. Also check the Aborting database transaction paragraph of the OutSystems exception handler documentation.
That is bad practice to create server actions that have the same name as OutSystems provided server actions.
If in your ListAll server action an exception occurs, and it is not handled there with an Exception handler, then ListAppend will not be called, and the exception will bubble up to the first exception handler that will catch it.
Thanks Daniel for clarifying. Now, My other question is
If exception occurs in second server/service call (that is ListAppend), what is the outcome? Will it rollback the first call (ListAll) or not?
Now, I am clear Thank you so much