-
Hi, I think I found something that can raise a "Bad state: This database has already been closed" error when executing a certain call inside a
And the
See that Moor is sending COMMIT TRANSACTION before the collection inserts are complete. I think this is caused by the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Essentially, this is a misuse of the As you mentioned, using an async callback in To avoid this confusion, moor should add checks throwing an error if a completed transaction is still being used. |
Beta Was this translation helpful? Give feedback.
Essentially, this is a misuse of the
transaction
api. Moor won't be able to fix this, but we should at least report a much better error message in this case.As you mentioned, using an async callback in
forEach
will schedule async work without awaiting it. The transaction will be closed after call toforEach
, but before all of the insert calls are completed.The workaround in this case is to use
await Future.wait(someCollection.map((element) async {}))
, which will wait for everything to complete.To avoid this confusion, moor should add checks throwing an error if a completed transaction is still being used.