Skip to content
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

SyncKit is receiving records with nil for non-optional CD fields. #140

Open
Rodge73 opened this issue Dec 18, 2020 · 2 comments
Open

SyncKit is receiving records with nil for non-optional CD fields. #140

Rodge73 opened this issue Dec 18, 2020 · 2 comments

Comments

@Rodge73
Copy link

Rodge73 commented Dec 18, 2020

Hi,
Nil values on iCloud CloudKit causing errors.

In my CoreData model there is Consult entity that has mandatory fields for date, moddate (record modification date )and creadate (record creation date). Moddate and creadate are actually determined (together with the uniqueIdentifier) in the awakeFromInsert(), moddate is updated by the willSave() method. A user doesn’t have any way to influence values for creaDate and modDate. Also the date field is mandatory, but app will give an error if the user tries to save without having entered a valid Date. As these 3 fields are mandatory (non optional attributes), CoreData won’t save the record without being present.

Now I have a seemingly rare condition that SyncKit sync is failing because of several but not all Consult records missing these values. So it seems SyncKit is downloading fine, but the CD doesn’t allow saving them. The error I get is (not a ckerror, but an error provided by CD):

Optional(Error Domain=NSCocoaErrorDomain Code=1560 "Multiple validation errors occurred." UserInfo={NSDetailedErrors=(
    "Error Domain=NSCocoaErrorDomain Code=1570 \"creaDate is a mandatory value.\" UserInfo={NSValidationErrorObject=<Consult: 0x220058e90> (entity: Consult; id: 0x2afa576b4869e521 <x-coredata://C336B6F2-53BC-4B5D-2EF4-253FB229DBAC/Consult/p11638>; data: <fault>), NSValidationErrorKey=creaDate, NSLocalizedDescription=creaDate is a mandatory value.}",
    "Error Domain=NSCocoaErrorDomain Code=1570 \"date is a mandatory value.\" UserInfo={NSValidationErrorObject=<Consult: 0x220058e90> (entity: Consult; id: 0x2afa576b4869e521 <x-coredata:// C336B6F2-53BC-4B5D-2EF4-253FB229DBAC /Consult/ p11638>; data: <fault>), NSValidationErrorKey=date, NSLocalizedDescription=date is a mandatory value.}",
    "Error Domain=NSCocoaErrorDomain Code=1570 \"modDate is a mandatory value.\" UserInfo={NSValidationErrorObject=<Consult: 0x220058e90> (entity: Consult; id: 0x2afa576b4869e521 <x-coredata:// C336B6F2-53BC-4B5D-2EF4-253FB229DBAC /Consult/ p11638>; data: <fault>), NSValidationErrorKey=modDate, NSLocalizedDescription=modDate is a mandatory value.}",
    "Error Domain=NSCocoaErrorDomain Code=1570 \"creaDate is a mandatory value.\" UserInfo={NSValidationErrorObject=<Consult: 0x27402ca43> (entity: Consult; id: 0x8aea576b4969e591 <x-coredata://B326E632-53BC-4BB3-8E24-2239E889D3EC/Consult/p14562>; data: <fault>), NSValidationErrorKey=creaDate, NSLocalizedDescription=creaDate i is a mandatory value.}",
…

This repeated for about 20 but not all Consult records. These 3 fields and the uniqueIdentifier are the only non-optional fields. But the error only mentions the 3 dates, but not nil for the uniqueIdentifier. So as there is no 1570 error for nil on unqueId I’m assuming it’s not nil, or SyncKit would assign something to it before saving.

I can reproduce the same error by going into Apple’s cloudkit webinterface and manually deleting one of these values (of course I can only do this with the dev account). Then starting a SyncKit sync.

Any idea how it’s possible that -somehow- in iCloud multiple records would have become nil values (for at least these fields, maybe more)? Normally this shouldn’t be possible, but somehow it did. What can be done to avoid this? Could this be caused by a bug in SyncKit?
Of course there is no way for a user to correct this, besides deleting all data in CloudKit and to sync again.

SyncKit v 0.8.0 on iOS 14.3.

In Consult+CoreDataProperties.swift:

  override public func awakeFromInsert() {
    super.awakeFromInsert()
    if uniqueIdentifier ==  nil {
      self.uniqueIdentifier = ProcessInfo.processInfo.globallyUniqueString
      self.creaDate = NSDate()
      self.modDate = self.creaDate
    }
  }
  override public func willSave() {
    super.willSave()

    if self.modDate == nil || now.timeIntervalSince(self.modDate! as Date) > 20 {
      self.modDate = NSDate()
    }
  }

Thanks,
Rodge

@mentrena
Copy link
Owner

Could you have a look at the records before they're uploaded (you can place a breakpoint here) and when they're downloaded (here) ? To get an idea of where the fields are going missing.

@Rodge73
Copy link
Author

Rodge73 commented Dec 21, 2020

Unfortunately I don't have access to the device, only to the errorlogs it's producing. So cannot really debug. As mentioned the only way I found to reproduce getting a similar errormesage, but also not fully sure this is the exact same issue, or how it's caused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants