Transactions not saving changes #340

Closed
opened 2025-12-29 15:29:31 +01:00 by adam · 3 comments
Owner

Originally created by @iby on GitHub (Aug 28, 2020).

Either I'm doing something stupid or got a really weird one… The following is performed on the main thread, tried with waitForAllObservers: false and asynchronous. It runs fine, other observers get notified of changes, all goes smoothly. As soon as I reload the app I see models showing old unmodified data.

try CoreStoreDefaults.dataStack.perform(synchronous: { transaction in
    guard let model = transaction.edit(model) else { throw ModelError.cannotEdit }
    Swift.print(">>>", "transaction.hasChanges: \(transaction.hasChanges), model.hasChanges: \(model.hasChanges), equal: \(model.exportURL == newExportURL)")
    model.exportURL = newExportURL
    Swift.print("<<<", "transaction.hasChanges: \(transaction.hasChanges), model.hasChanges: \(model.hasChanges), equal: \(model.exportURL == newExportURL)")
})
// >>> transaction.hasChanges: false, model.hasChanges: false, equal: false
// <<< transaction.hasChanges: false, model.hasChanges: true, equal: true

What's weird is that model reports changes after updating, but transaction isn't. The model object looks as follows:

public final class Model: NSManagedObject {
    @NSManaged public var date: Date
    @NSManaged public var documentURL: URL?
    @NSManaged public var exportURL: URL
}

Can you think of anything what might be causing this?

Originally created by @iby on GitHub (Aug 28, 2020). Either I'm doing something stupid or got a really weird one… The following is performed on the main thread, tried with `waitForAllObservers: false` and asynchronous. It runs fine, other observers get notified of changes, all goes smoothly. As soon as I reload the app I see models showing old unmodified data. ```swift try CoreStoreDefaults.dataStack.perform(synchronous: { transaction in guard let model = transaction.edit(model) else { throw ModelError.cannotEdit } Swift.print(">>>", "transaction.hasChanges: \(transaction.hasChanges), model.hasChanges: \(model.hasChanges), equal: \(model.exportURL == newExportURL)") model.exportURL = newExportURL Swift.print("<<<", "transaction.hasChanges: \(transaction.hasChanges), model.hasChanges: \(model.hasChanges), equal: \(model.exportURL == newExportURL)") }) // >>> transaction.hasChanges: false, model.hasChanges: false, equal: false // <<< transaction.hasChanges: false, model.hasChanges: true, equal: true ``` What's weird is that model reports changes after updating, but transaction isn't. The model object looks as follows: ```swift public final class Model: NSManagedObject { @NSManaged public var date: Date @NSManaged public var documentURL: URL? @NSManaged public var exportURL: URL } ``` Can you think of anything what might be causing this?
adam closed this issue 2025-12-29 15:29:31 +01:00
Author
Owner

@iby commented on GitHub (Aug 28, 2020):

Ah yes, I'm an epic moron. Never mind me… 🤦‍♂️

@iby commented on GitHub (Aug 28, 2020): Ah yes, I'm an epic moron. Never mind me… 🤦‍♂️
Author
Owner

@gardyna commented on GitHub (Dec 10, 2020):

@ianbytchek thanks for the helpfull comment. can you please tell me what was wrong?

@gardyna commented on GitHub (Dec 10, 2020): @ianbytchek thanks for the helpfull comment. can you please tell me what was wrong?
Author
Owner

@iby commented on GitHub (Dec 10, 2020):

To be honest I don't remember, but I think I was editing a model that was not saved.

@iby commented on GitHub (Dec 10, 2020): To be honest I don't remember, but I think I was editing a model that was not saved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#340