caiyue1993 / IceCream

Sync Realm Database with CloudKit
MIT License
1.93k stars 243 forks source link

Relationships recover but not to the original parent class #238

Closed mohitnandwani closed 3 years ago

mohitnandwani commented 3 years ago

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

caiyue1993 commented 3 years ago

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.

caiyue1993 commented 3 years ago

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?

mohitnandwani commented 3 years ago

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).

caiyue1993 commented 3 years ago

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!

mohitnandwani commented 3 years ago

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!

elliotcz97 commented 3 years ago

@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!

caiyue1993 commented 3 years ago

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!

elliotcz97 commented 3 years ago

@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:

Then after upload i could get:

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)

caiyue1993 commented 3 years ago

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!

elliotcz97 commented 3 years ago

@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.

kyashan commented 1 year ago

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?