mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 22:30:34 +01:00
Transaction Changes Not Merged or Triggering Publishers #441
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Devenias on GitHub (Jan 30, 2025).
I have an issue with transactions and publishers.
When I update existing models in a
.performblock with it's transaction contexttransaction.fetchOnethe 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.fetchOneinstead, 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:
@JohnEstropia commented on GitHub (Feb 3, 2025):
dataStack.performdoes not wait for completion ofdataStack.addStorage()and it's likely you are fetching earlier than the storage has been added to theDataStack@Devenias commented on GitHub (Feb 3, 2025):
Thanks for the response, but I use a singleton to make sure the
DataStackis initialized properly and use.addStorageAndWait()in the appsfunc application(didFinishLaunchingWithOptions: ).@JohnEstropia commented on GitHub (Feb 4, 2025):
Are you running parallel updates on the same entities? I'd also check the following:
performis not emitting errors@Devenias commented on GitHub (Feb 6, 2025):
The
performis not emitting any errors, I get a.successin thecompletion.And when I use
.fetchOnein thecompletion, the values are not updated in the result.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
.perform(synchronous:)and a serialDispatchQueue.It works in my test project and the updates are synchronised, the data is changed and the publisher triggered.
But when I want to apply the same approach to my existing project it does not work anymore (same behaviour as before). I have to figure out what the differences are.
Do you have any other idea how I can prevent parallel updates or synchronise them properly?
@JohnEstropia commented on GitHub (Feb 10, 2025):
@Devenias Can you try these?
try?here and just calltrynormally?updateWith(entity:)method setsMyModel. id