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

Nested transaction partially commits outer transaction since 0.16.1 #605

Closed
toefel18 opened this issue Jul 13, 2019 · 4 comments
Closed
Assignees
Labels

Comments

@toefel18
Copy link
Contributor

toefel18 commented Jul 13, 2019

The nested transaction commits prior work of the outer transaction when the nested transaction scope ends. A rollback after the nested transaction is ineffective and results in an incorrect state.

Default nested transaction handling seems incorrect after upgrading from 0.14.1 to 0.16.1.

(I have read https://github.com/JetBrains/Exposed/wiki/Transactions#using-nested-transactions, but it is not thourough)

Consider this nested transaction:

       transaction {
            Actors.insert {   it[firstName] = "before-dummy"     }
            transaction {
                Actors.insert {   it[firstName] = "inner-dummy"     }
            }
            Actors.insert {   it[firstName] = "after-dummy"     }
            rollback()
        }

Behavior version 0.14.1
before-dummy <- rolled back!
inner-dummy <- rolled back!
after-dummy <- rolled back!

Behavior version 0.16.1 with db.useNestedTransactions = false (default)
before-dummy <- written to database
inner-dummy <- written to database
after-dummy <- rolled back!
Observed behavior: The nested transaction seems to commit the first part (before-dummy) of the outer transaction when it goes out of scope.
Expected: it does not commit and leaves committing to the outer transaction (or less preferred: the inner transaction only commits work in it's own scope).

Behavior version 0.16.1 with db.useNestedTransactions = true
before-dummy <- rolled back!
inner-dummy <- rolled back!
after-dummy <- rolled back!
This behaves as expected (although one could also expect inner-dummy to be committed!)

Without using db.useNestedTransactions = true nested transactions seem broken.

Preferred solution in my opinion would be an extra parameter for transaction(){} which specifies the desired transaction propagation. For example:

transaction {
     Actors.insert {}
     transaction(REQUIRES_NEW) {
        // new transaction that commits when out of sope
     }
}

A bit like the options provided by Spring https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Propagation.html

@toefel18 toefel18 changed the title Nested transaction commits outer transaction since 1.16.1 Nested transaction partially commits outer transaction since 1.16.1 Jul 13, 2019
@toefel18 toefel18 changed the title Nested transaction partially commits outer transaction since 1.16.1 Nested transaction partially commits outer transaction since 0.16.1 Jul 14, 2019
@toefel18
Copy link
Contributor Author

toefel18 commented Jul 20, 2019

Any updates on this?

@Tapac
Copy link
Contributor

Tapac commented Jul 24, 2019

Fixed in 0.16.3.

@toefel18 , I'll think about how to implement propagation in the future releases

@binkley
Copy link

binkley commented Jul 25, 2019

Hi, ChangeLog.md lists this issue as fixed (as stated by #605 (comment), above). However, this issue in GitHub is still in Open state.

Should this issue be closed, or is it kept open for discussing propagation? I see #611 is opened.

@Tapac
Copy link
Contributor

Tapac commented Jul 25, 2019

@binkley , thnx, I just forgot to close an issue.

@Tapac Tapac closed this as completed Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants