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

Cancel transactions on all kind of exceptions #1621

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Fixed
* Using keypaths in Flows could sometimes throw `java.lang.IllegalStateException: [RLM_ERR_WRONG_THREAD]: Realm accessed from incorrect thread.`. (Issue [#1594](https://github.com/realm/realm-kotlin/pull/1594, since 1.13.0)
* Non-`IllegalStateExceptions` in a `write`-block would not cancel transactions, but leave it open. (Issue [#1615](https://github.com/realm/realm-kotlin/issues/1615)).

### Compatibility
* File format: Generates Realms with file format v23.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ internal class SuspendableWriter(
if (shouldClose.value)
throw IllegalStateException("Cannot commit transaction on closed realm")
}
} catch (e: IllegalStateException) {
} catch (e: Throwable) {
if (realm.isInTransaction()) {
realm.cancelWrite()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class RealmTests {

@Suppress("invisible_member")
@Test
fun exceptionInWriteWillRollback() = runBlocking {
fun exceptionInWriteWillRollback() = runBlocking<Unit> {
class CustomException : Exception()

assertFailsWith<CustomException> {
Expand All @@ -189,6 +189,11 @@ class RealmTests {
}
}
assertEquals(0, realm.query<Child>().find().size)
// Verify that we can do additional transactions after the previous transaction
// was rolled back due to the exception
realm.write {
this.copyToRealm(Child())
}
}

@Test
Expand Down