You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This occurs because I define a shared global resource for the database accessed inside a method handler.
final db =Nitric.sql('db');
final api =Nitric.api('api');
voidmain(List<String> arguments) {
api.get("/hello", (ctx) async {
/// Causes database resource to be createdawait db.connectionString();
return ctx;
});
}
The hypothesis posed by @tjholm is that globally defined variables are lazily evaluated. We could verify this by reassigning the database resource inside of main:
final db =Nitric.sql('db');
final api =Nitric.api('api');
voidmain(List<String> arguments) {
/// Causes database resource to be createdfinal myDb = db;
api.get("/hello", (ctx) async {
await myDb.connectionString();
return ctx;
});
}
Other resources such as the previously defined api don't have this problem because they are initialized or referenced directly inside of the main function for each service.
Applying recommendations for Option 2 in: nitrictech/cli#812 and updating the Dart guides for resource sharing are probably the best way to address this.
Bug Report
Issue
Upon deploying, I see the following runtime error when attempting to hit an endpoint that pulls data from the SQL Database:
This occurs because I define a shared global resource for the database accessed inside a method handler.
The hypothesis posed by @tjholm is that globally defined variables are lazily evaluated. We could verify this by reassigning the database resource inside of
main
:Other resources such as the previously defined
api
don't have this problem because they are initialized or referenced directly inside of themain
function for each service.Steps
Steps to reproduce the behavior:
Attempt to deploy the following project: https://github.com/chimon2000/db-deploy-issue
Expected
The database is created and seeded before the API is referenced.
Environment and setup information
Other info
Conversation thread: https://discord.com/channels/955259353043173427/999455789146181683/1287084311916445727
The text was updated successfully, but these errors were encountered: