mariiaKraievska commented on code in PR #3555:
URL: https://github.com/apache/fineract/pull/3555#discussion_r1386613016


##########
fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java:
##########
@@ -139,7 +139,8 @@ public CommandProcessingResult executeCommand(final 
CommandWrapper wrapper, fina
             
commandSource.setCommandJson(toApiJsonSerializer.serializeResult(result.getChanges()));
         }
 
-        commandSource = 
commandSourceService.saveResultSameTransaction(commandSource);
+        commandSource = sameTransaction ? 
commandSourceService.saveResultSameTransaction(commandSource)
+                : commandSourceService.saveResultNewTransaction(commandSource);

Review Comment:
   > Can you please explain why you had "403 - Dublicate entry key" and how 
save in new transaction helps? As this is the success branch, it actually does 
not matter if we save in the same or in new transaction, in both cases it will 
be saved. Please make sure that you do not save new instance for each retry. 
What is not happening right now is to save the command even if it was failed, 
so the code that you should change is in the catch (Throwable t) branch: 
instead of saveResultSameTransaction for 'sameTransaction' we should call 
'saveResultNewTransaction' each time. But what is missing though, is to set the 
failed code at the end.
   
   Due to the fact that the saveInitialSameTransaction was called instead of 
saveInitialNewTransaction, unsuccessful sub-requests were not logged to the 
audit trail (we are talking about the case when enclosingTransaction=false when 
calling BatchAPI, since this is exactly the case described in the task, as far 
as I understand). When I made it so that when enclosingTransaction=false, 
saveInitialNewTransaction was called, unsuccessful sub-requests began to be 
logged to the audit trail, but a new problem arose: after executing 
saveInitialNewTransaction, the database already contained a transaction with a 
unique key binding (action_name, entity_name, idempotency_key) in table 
"m_portfolio_command_source". Therefore, when calling the 
saveResultSameTransaction below, the error "403 - Dublicate entry key" began to 
return, because the database already had a record with the same key. You can't 
use saveInitialNewTransaction first and saveResultSameTransaction below on the 
same entity - this ca
 n lead to data inconsistency or re-saving data (as it happened to me). What 
about the duplication, there is no duplication, because saveAndFlush works as 
follows: if there is a record in the database, it updates it, if not, it 
creates it (let's ignore the data inconsistency problems that I described 
earlier). 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to