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

Starting a write transaction inside a write transaction will rollback the original transaction #442

Closed
nirinchev opened this issue Mar 29, 2022 · 0 comments · Fixed by #448
Assignees

Comments

@nirinchev
Copy link
Member

nirinchev commented Mar 29, 2022

The following awkward code fails in an even more awkward way:

final config = Configuration([Car.schema]);
final realm = Realm(config);
realm.write(() {
  // Second write inside the first one fails but the error is caught
  try {
    realm.write(() {});
  } catch (ex) {}
});

The error is:

RealmException: Could not commit write. Error code: 5 . Message: Can't commit a non-existing write transaction

What ends up happening is

  1. We start the outer write
  2. We start inner write
  3. Inner write fails
  4. We hit the realm.write catch block, which rolls back the outer transaction and rethrows
  5. We catch the exception from the inner write
  6. Realm tries to commit the outer write, which fails because the transaction was rolled back in 4.
@nirinchev nirinchev self-assigned this Mar 30, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant