LateInitializationError from _connectedDb when querying from isolate #1570
-
I am here again to ask for some assistance: In my app, I use When I launch the app, in my DatabaseConnection connection = DatabaseConnection.delayed(isolate.connect()); Which I then use in my (multi) provider s.t. I can access it throughout my app: Provider<MyDatabase>(
create: (context) => MyDatabase.connect(connection),
dispose: (context, db) => db.close(),
) So far, so good. However, when I first access the database, I do so from another isolate (which is responsible for fetching data from the server), and in doing so, I get a After messing around for a bit, I found out I could prevent it by performing a query from the main isolate, which seems to force everything to initialize. That is, before I start the isolate that fetches and stores the data, I run MyDatabase db = Provider.of<MyDatabase>(context, listen: false);
// query the items table (empty at this time) and just ignore the result
await db.allItems().get();
startDataLoadingIsolate(); The question is, is this expected behaviour? Am I doing something wrong, or is this a bug? Not sure if this is better fitted as a discussion topic or as an issue, it depends on what causes the problem for me, I suppose ;) Stack trace for the error
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
I feel like this is a drift issue. If this turns out to be you doing something wrong, we should at least report a much more actionable error message ;) If you can consistently reproduce this, could you enable |
Beta Was this translation helpful? Give feedback.
I feel like this is a drift issue. If this turns out to be you doing something wrong, we should at least report a much more actionable error message ;)
If you can consistently reproduce this, could you enable
debugLog: true
when callingDriftIsolate.connect
? It would be interesting to see the messages being sent across isolates before this happens. If you share a bit more details on how you start the second isolate (where the error happens, I can also try to reproduce this myself). But maybe seeing the debug log will be enough.