-
-
Notifications
You must be signed in to change notification settings - Fork 803
Closed
Labels
Description
After upgrading to GRDB 7.7.0 from GRDB 7.6.1 I noticed that several of my unit tests started to fail. Specifically, it seems like something about the .saved() method seems to have changed. I narrowed down the failure to a code snippet like this, where we start with an empty, in-memory database:
try await appDatabase.writer.write { db in
_ = try food1.food.saved(db)
_ = try food2.food.saved(db)
_ = try serving1.saved(db)
_ = try serving2.saved(db)
_ = try section.saved(db)
}
In this instance serving1 has a foreign key dependency on on food and I get the following error:
Test "Test frequently paired foods" recorded an issue at FrequentlyPairedFoodsTests.swift:14:4:
Caught error: SQLite error 19: FOREIGN KEY constraint failed - while executing `INSERT INTO "serving" ("id", "description", "nutritionMultiplier", "amount", "measure", "metricUnit", "metricValue", "sortOrder", "isPublic", "derivedFrom", "nutritionPanelId", "foodId") VALUES (?,?,?,?,?,?,?,?,?,?,?,?)` with arguments ["eb46ddbf-e15b-4be2-8daa-8ab83c657953", "1 piece", 1.0, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL, "food2"]
If I replace the saved calls here with inserted, the tests pass again. Hopefully this is enough info to go on, but if not, I'm happy to try to create a sample project.
Environment
- Xcode 26.0
- iOS 26.0