Saga with raise inside SagaActionStep don't rollback
Hi, there is a problem if raise happened inside SagaActionStep then saga don't rollback action, but return Either.Left. Example code:
suspend fun main() {
// perform the transaction
val result = either {
saga {
saga({
raise("failed")
println("Action A")
}) { println("Rollback A") }
}.transact()
}
println(result)
}
Arrow version: 1.2.4
What printout are you getting, and what's your expected output?
What printout are you getting, and what's your expected output?
It printed Either.Left and that was all. I expected it to run a rollback and print "Rollback A" and return Either.Left.
@outlndrr that should indeed result in rolling back the action. Thank you for reporting this issue, I think this is fixed on 2.0.0 but might be missing a test case. So leaving this issue open!
@outlndrr the behavior you see is actually correct. A saga block will undo every action which has succeeded, and the block where you have raise is not considered successful yet, since it hasn't fully executed. Think of the case of a database, if some part of the transaction has failed, you don't have to roll that one back, since it's already failed.
I've added a few tests as part of 103848035bf382126b10857136e8fc2fc1657286, and you can see there that if you have other saga blocks before the one that raises, those are rolled back as expected.