aaronpearce / Harmony

Harmony provides CloudKit sync for GRDB and only GRDB.
Other
125 stars 10 forks source link

Multiple model variables that include ID interfere with CloudKit sync. #7

Open haIIux opened 5 months ago

haIIux commented 5 months ago

If the user has a model that has more than one object in which has the word ID or id in it, the func nextRecordZoneChangeBatch on Line 192, the return on Line 206 will return a null record. This means that there will be no CloudKit sync possible and there is no specific error reflecting this.

Unsure if this is relevant to #3.

// Bad Model
struct Achievement: HRecord, Codable, Identifiable, Hashable {
    var id: UUID = UUID()
    var achievementID: String

    var zoneID: CKRecordZone.ID {
        return CKRecordZone.ID(
            zoneName: "Achievement",
            ownerName: CKCurrentUserDefaultName
        )
    }

    var archivedRecordData: Data?

    var record: CKRecord {
        let encoder = CKRecordEncoder(zoneID: zoneID)
        return try! encoder.encode(self)
    }
}

// Acceptable Model
struct Achievement: HRecord, Codable, Identifiable, Hashable {
    var id: UUID = UUID()
    var achievementType: String

    var zoneID: CKRecordZone.ID {
        return CKRecordZone.ID(
            zoneName: "Achievement",
            ownerName: CKCurrentUserDefaultName
        )
    }

    var archivedRecordData: Data?

    var record: CKRecord {
        let encoder = CKRecordEncoder(zoneID: zoneID)
        return try! encoder.encode(self)
    }
}
aaronpearce commented 4 months ago

I'll see if I can replicate this in the near future. Definitely some more checks could be added.

dehlen commented 1 month ago

Are there any insights to this? I currently have no access to a paid developer account so I can't test this behaviour but I am wondering whether this is related to the recordID parsing or the CloudKit Codable implementation. I am currently looking at your package as one way for me to add syncing to a future app but I would like more insights on this bug as I think it could easily trip me up in the future.

aaronpearce commented 3 weeks ago

@dehlen I haven't dived deep into this bug as of yet to reproduce it and confirm it is an active bug still.