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

Updating a property in a transaction does not work #305

Open
fvisticot opened this issue Feb 19, 2022 · 1 comment
Open

Updating a property in a transaction does not work #305

fvisticot opened this issue Feb 19, 2022 · 1 comment

Comments

@fvisticot
Copy link

The following code never complete the RES1 step and no exception is fired

try {
      await _db.transaction((txn) async {
        StoreRef storeRef = intMapStoreFactory.store(kBeaconsStore);

        for (final rec in records) {
          final record = storeRef.record(int.parse(rec.id));
          if (await record.exists(_db)) {
            final res = await record.get(_db);
            print("RES: $res");
            final res1 = await record.update(_db, {'isFlushed': true});
            print("RES1: $res1");
          } else {
            print("Record with id ${rec.id} not found");
          }
        }
      });
    } catch (e) {
      throw BeaconLocationStoreException('[markRecordsAsFlushed] $e');
    }

This code is working (removing the transaction)

StoreRef storeRef = intMapStoreFactory.store(kBeaconsStore);
    for (final rec in records) {
      final record = storeRef.record(int.parse(rec.id));
      if (await record.exists(_db)) {
        final res = await record.get(_db);
        print("RES: $res");
        final res1 = await record.update(_db, {'isFlushed': true});
        print("RES1: $res1");
      } else {
        print("Record with id ${rec.id} not found");
      }
    }
@alextekartik
Copy link
Collaborator

Yes that is a deadlock, since you are trying to use the database in a transaction rather than using the transaction itself. See a note about that here:
https://github.com/tekartik/sembast.dart/blob/master/sembast/doc/transactions.md#dead-lock

basically you should not do:

final res = await record.get(_db);

but

final res = await record.get(txn);

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

2 participants