-
-
Notifications
You must be signed in to change notification settings - Fork 255
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
Transaction Changes Not Merged or Triggering Publishers #514
Comments
|
Thanks for the response, but I use a singleton to make sure the func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
print("Database version: \(DatabaseStack.instance.dataStack.modelVersion)")
// ...
}
class DatabaseStack {
static let instance = DatabaseStack()
let dataStack = DataStack(xcodeModelName: "DataModel")
private init() { initialize() }
private func initialize() {
do {
try dataStack.addStorageAndWait(
SQLiteStore(
fileName: "MyDatabase.sqlite",
localStorageOptions: [
.allowSynchronousLightweightMigration,
.recreateStoreOnModelMismatch
]
)
)
} catch let error {
fatalError("Could not initialize database: \(error.localizedDescription)")
}
CoreStoreDefaults.dataStack = dataStack
CoreStoreDefaults.logger = DatabaseLogger()
}
} |
Are you running parallel updates on the same entities? I'd also check the following:
|
The And yes, the updates might run in parallel. I started a new test project to isolate the issue and I can reproduce it. Then I tried to fix it using serialQueue.async {
do {
try DatabaseStack.instance.dataStack.perform(synchronous: { transaction in
// ...
})
// in my existing project I tried to fetch immediately after the perform(synchronous:), but the data has not changed.
} catch {
// ...
}
} It works in my test project and the updates are synchronised, the data is changed and the publisher triggered. |
@Devenias Can you try these?
try? transaction.fetchOne(fetch)
|
I have an issue with transactions and publishers.
When I update existing models in a
.perform
block with it's transaction contexttransaction.fetchOne
the data is not correct after execution, still has the old data and does not trigger the publisher. So my UI never noticed a change, because it did not happen.When I use
DatabaseStack.instance.dataStack.fetchOne
instead, I can edit the object and it also triggers the data update on the publisher. I'm I doing something wrong or is that a bug, that the transaction context is not fully merged into the main context?I'm using CoreStore 9.2.0 because I have to support iOS 15.
I get some new data and update in an async transaction:
and I observe it like that:
The text was updated successfully, but these errors were encountered: