Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saga with raise inside SagaActionStep don't rollback #3458

Closed
outlndrr opened this issue Jun 18, 2024 · 4 comments
Closed

Saga with raise inside SagaActionStep don't rollback #3458

outlndrr opened this issue Jun 18, 2024 · 4 comments

Comments

@outlndrr
Copy link

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

@kyay10
Copy link
Collaborator

kyay10 commented Jun 18, 2024

What printout are you getting, and what's your expected output?

@outlndrr
Copy link
Author

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.

@nomisRev
Copy link
Member

@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!

serras added a commit that referenced this issue Jan 26, 2025
@serras
Copy link
Member

serras commented Jan 26, 2025

@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 1038480, and you can see there that if you have other saga blocks before the one that raises, those are rolled back as expected.

@serras serras closed this as completed Jan 26, 2025
serras added a commit that referenced this issue Jan 26, 2025
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

No branches or pull requests

4 participants