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 transactions and rollbacks. #534

Closed
spand opened this issue Mar 26, 2019 · 5 comments
Closed

Nested transactions and rollbacks. #534

spand opened this issue Mar 26, 2019 · 5 comments

Comments

@spand
Copy link
Contributor

spand commented Mar 26, 2019

After working a bit with manual rollbacks and nested transaction {} blocks it seems that a call to rollback() will rollback the current db transaction but otherwise let db work continue in a transaction {} block.

This isnt quite what I expected. I think I would expect a transaction to be either in an open or closed state and any call to either commit() or rollback() would close it requiring a new top level transaction block to start db work again (or maybe let it continue if in a top level transaction). Not let the "sub transaction" continue doing db work and certainly not the top level transaction {} block after a nested one has triggered a rollback.

Thoughts ?

@antanas-arvasevicius
Copy link

I've encountered with the same issue, had made PR to fix this: #544

@swistaczek
Copy link

Hey guys, I encountered the same error.

@Tapac
Copy link
Contributor

Tapac commented Jul 4, 2019

Fixed in master will be released soon.

@Tapac Tapac closed this as completed Jul 4, 2019
@spand
Copy link
Contributor Author

spand commented Jul 5, 2019

Not that I dont appreciate actual nested transaction support but it is a bit unrelated to my issue.. which is what should happen with nested exposed transaction blocks in the case of db.useNestedTransactions = false.

What I suggested something like this:

    @Test(expected = ExposedSQLException::class)
    fun rollbackClosesTransactionBlock() {
        withTables(DMLTestsData.Cities) {
            rollback()
            DMLTestsData.Cities.selectAll() // throws exception because connection is now closed
            fail()
        }
    }

    @Test(expected = ExposedSQLException::class)
    fun nestedRollbackClosesOuterTransactionBlock() {
        withTables(DMLTestsData.Cities) {
            transaction {
                rollback()
            }
            DMLTestsData.Cities.selectAll() // throws exception because connection is now closed
            fail()
        }
    }

@Tapac
Copy link
Contributor

Tapac commented Jul 5, 2019

@spand, there are cases when you want to make commit to flush changes to the database and continue to work with your code, same for a rollback.

Maybe additional functions like rollbackAndClose should be introduced?

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