caiyue1993/IceCream

Relationships recover but not to the original parent class

Closed this issue · 11 comments

Expected behavior

Relationships should recover properly to the records/objects they belong.

Actual behavior

Relationships recover but not to the original parent class. Instead they get added to random objects and update records in CloudKit causing loss of original data.

Steps to reproduce the problem

• Use example to add data and sync it with CloudKit
• Uninstall the app and delete all files
• Reinstall app and let it recover data from CloudKit and you'll see relationships not recovering properly and get added to random objects
• Visit CloudKit dashboard and you'll find that your data is now updated with new/wrong relationships

Hi @mohitnandwani , really appreciate it for proposing this issue and I've noticed this bug as well. I'll take some time to fix it and will let you know.

And I've found the CloudKit Console(which was CloudKit dashboard) always shows the below error message when I try to query records:

"Field 'recordName' is not marked queryable"

I've tried some ways to make it work but it failed. Have you guys encountered this problem?

Hey @caiyue1993 , Thanks for your reply! Yeah it does show the error when querying records on CloudKit without any filter. What I usually do is to query records with "isDeleted" filter in the new console. Also it seems that the bug happen with the pendingRelationshipWorker appending relationship to random objects during the first sync. (Inside the CKRecordRecoverable, when its converting the CKReference to List).

Hi @mohitnandwani , thanks for your suggestion! Now I can successfully query records in CloudKit Console. And I think I've found the reason behind this relationships recover issue. I've submitted PR #240.
The fix branch name is fix/issue-238. How about giving it a try when you have time? We'll merge that PR if it fixes.
Thank you again!

Hey @caiyue1993 👋🏽! Thank you so much for looking into this! Will definitely look into this and get back to you as soon as I can!

@caiyue1993 I used your fix in the PR #240 yesterday, because i had the same problem as the OP!
It fixed the issue, now the list elements don't spread randomly across other parents lists. I tested it only Yesterday, but if you want i can give a long term review after the weekend!

Thank you @elliotcz97! Sorry for the delayed response. Yes please give it a long term review and give us your feedback when you have time!

@caiyue1993
So, to be short it works great, and it fixes the problem, however what i noticed, that the list elements get rearanged, for example if i have list:

  • Eggs
  • Milk
  • Butter

Then after upload i could get:

  • Butter
  • Egg
  • Milk

And i think, for now, i cannot confirm it, but i have a feeling that my problem #242 has to do something with this.
To be short if i alter a list item on one device, then it gets uploaded, but the old item on the other device gets pulled back after a while.
(this happens only with clases containing relationships, so thats why i think it could be related)

Hi @elliotcz97, yeah it may be the same cause. As for the rearranged elements it's acceptable. You could add index property onto every element to order them.
So, #240 is ready to be merged. Thank you all!

@caiyue1993 thanks for your idea, i already did that ( giving index property). I hope you can find a solution for my issue too, Have a nice day.

Hi @elliotcz97, yeah it may be the same cause. As for the rearranged elements it's acceptable. You could add index property onto every element to order them. So, #240 is ready to be merged. Thank you all!

I have the same problem with random reordering of list elements. Any solution for this?