Start a new topic

KCSCachedStore Query Posts with User Relation

I have a function that fetches posts from a regular (KCSLinkedAppDataStore) collection store that works fine. It returns a dictionary of values that I use to populate a tableview. I want to use the KCSCachedStore to retrieve the same data with a NetworkFirst call. 


The application crashes with 'Invalid type in JSON write (KCSUser)' when using NetworkFirst. Every post has one associated user. If I change the cache policy to None, it works (because it is just querying the server. 


            Kinvey_Store.postCacheStore.queryWithQuery(query, withCompletionBlock: { (posts, error) in
                guard let postArray = posts as? [Kinvey_Post] where error == nil else {
                    block?(postDictionary: nil)
                    return
                }; Kinvey_Manager.enumeratePosts(postArray, withCompletionBlock: { (userArray, IdArray, shortURLArray) in
                    
                    // Code Deleted [...]
                    
                    dispatch_async(dispatch_get_main_queue(), {
                        block?(postDictionary: postDictionary)
                    })
                })
                }, withProgressBlock: nil, cachePolicy: KCSCachePolicy.NetworkFirst)

   


When I enumerate over the post objects that return from the cached store (even when cache policy it Both), no KCSUser objects return, but all of them return from the KCSLinkedAppdataStore. Here is the output: 


 

from cache store: [<Dormistory.Kinvey_Post: 0x7fd80853e830>, <Dormistory.Kinvey_Post: 0x7fd809b80880>, <Dormistory.Kinvey_Post: 0x7fd809bb7dd0>, <Dormistory.Kinvey_Post: 0x7fd809bbf700>, <Dormistory.Kinvey_Post: 0x7fd809b8b5d0>, <Dormistory.Kinvey_Post: 0x7fd809bac360>, <Dormistory.Kinvey_Post: 0x7fd809bb07f0>, <Dormistory.Kinvey_Post: 0x7fd809b7df30>, <Dormistory.Kinvey_Post: 0x7fd809bc3600>, <Dormistory.Kinvey_Post: 0x7fd809b15b60>, <Dormistory.Kinvey_Post: 0x7fd809bdd130>, <Dormistory.Kinvey_Post: 0x7fd809b13ed0>, <Dormistory.Kinvey_Post: 0x7fd809bc70f0>, <Dormistory.Kinvey_Post: 0x7fd809bc5c00>, <Dormistory.Kinvey_Post: 0x7fd809bd81f0>, <Dormistory.Kinvey_Post: 0x7fd809bb9b50>, <Dormistory.Kinvey_Post: 0x7fd809b0a190>, <Dormistory.Kinvey_Post: 0x7fd808438db0>, <Dormistory.Kinvey_Post: 0x7fd808422ee0>, <Dormistory.Kinvey_Post: 0x7fd80862a190>, <Dormistory.Kinvey_Post: 0x7fd80857ff00>, <Dormistory.Kinvey_Post: 0x7fd808569640>, <Dormistory.Kinvey_Post: 0x7fd80850f520>, <Dormistory.Kinvey_Post: 0x7fd80857f8a0>, <Dormistory.Kinvey_Post: 0x7fd808578640>, <Dormistory.Kinvey_Post: 0x7fd808578e00>, <Dormistory.Kinvey_Post: 0x7fd808431550>, <Dormistory.Kinvey_Post: 0x7fd80844dbc0>, <Dormistory.Kinvey_Post: 0x7fd808630ca0>, <Dormistory.Kinvey_Post: 0x7fd808591420>, <Dormistory.Kinvey_Post: 0x7fd808581be0>, <Dormistory.Kinvey_Post: 0x7fd808584530>, <Dormistory.Kinvey_Post: 0x7fd808585b20>, <Dormistory.Kinvey_Post: 0x7fd809bd3a70>, <Dormistory.Kinvey_Post: 0x7fd809b81050>, <Dormistory.Kinvey_Post: 0x7fd809bd37e0>, <Dormistory.Kinvey_Post: 0x7fd809bd87c0>, <Dormistory.Kinvey_Post: 0x7fd809baf200>, <Dormistory.Kinvey_Post: 0x7fd809be06c0>, <Dormistory.Kinvey_Post: 0x7fd809be21a0>, <Dormistory.Kinvey_Post: 0x7fd809be0c60>, <Dormistory.Kinvey_Post: 0x7fd809bdff10>]

from linked store: [<Dormistory.Kinvey_Post: 0x7fd80859a440>, <Dormistory.Kinvey_Post: 0x7fd80859fd20>, <Dormistory.Kinvey_Post: 0x7fd80859fe10>, <Dormistory.Kinvey_Post: 0x7fd808618030>, <Dormistory.Kinvey_Post: 0x7fd808644a20>, <Dormistory.Kinvey_Post: 0x7fd808632d10>, <Dormistory.Kinvey_Post: 0x7fd80860d740>, <Dormistory.Kinvey_Post: 0x7fd808650880>, <Dormistory.Kinvey_Post: 0x7fd80861da60>, <Dormistory.Kinvey_Post: 0x7fd808655d20>, <Dormistory.Kinvey_Post: 0x7fd808655dd0>, <Dormistory.Kinvey_Post: 0x7fd808641b80>, <Dormistory.Kinvey_Post: 0x7fd808656660>, <Dormistory.Kinvey_Post: 0x7fd808657810>, <Dormistory.Kinvey_Post: 0x7fd808658600>, <Dormistory.Kinvey_Post: 0x7fd8086586b0>, <Dormistory.Kinvey_Post: 0x7fd80865c8d0>, <Dormistory.Kinvey_Post: 0x7fd80865c980>, <Dormistory.Kinvey_Post: 0x7fd8086606d0>, <Dormistory.Kinvey_Post: 0x7fd808660780>, <Dormistory.Kinvey_Post: 0x7fd808661d40>, <Dormistory.Kinvey_Post: 0x7fd808662350>, <Dormistory.Kinvey_Post: 0x7fd80865ff70>, <Dormistory.Kinvey_Post: 0x7fd808664aa0>, <Dormistory.Kinvey_Post: 0x7fd8086656f0>, <Dormistory.Kinvey_Post: 0x7fd8086657a0>, <Dormistory.Kinvey_Post: 0x7fd808660f80>, <Dormistory.Kinvey_Post: 0x7fd808669570>, <Dormistory.Kinvey_Post: 0x7fd808669000>, <Dormistory.Kinvey_Post: 0x7fd808662dd0>, <Dormistory.Kinvey_Post: 0x7fd80866b270>, <Dormistory.Kinvey_Post: 0x7fd80866d7f0>, <Dormistory.Kinvey_Post: 0x7fd80866d340>, <Dormistory.Kinvey_Post: 0x7fd808670470>, <Dormistory.Kinvey_Post: 0x7fd80866c620>, <Dormistory.Kinvey_Post: 0x7fd80866e840>, <Dormistory.Kinvey_Post: 0x7fd808673370>, <Dormistory.Kinvey_Post: 0x7fd808674e20>, <Dormistory.Kinvey_Post: 0x7fd808671c20>, <Dormistory.Kinvey_Post: 0x7fd8086717b0>, <Dormistory.Kinvey_Post: 0x7fd808675da0>, <Dormistory.Kinvey_Post: 0x7fd808675910>]

linked store users
<KCSUser: 0x7fd8085a0210>
<KCSUser: 0x7fd8085a1610>
<KCSUser: 0x7fd808607950>
<KCSUser: 0x7fd808604120>
<KCSUser: 0x7fd808619e10>
<KCSUser: 0x7fd80860afc0>
<KCSUser: 0x7fd80861baa0>
<KCSUser: 0x7fd808642460>
<KCSUser: 0x7fd808655f20>
<KCSUser: 0x7fd808656860>
<KCSUser: 0x7fd808658840>
<KCSUser: 0x7fd80865a460>
<KCSUser: 0x7fd80865b910>
<KCSUser: 0x7fd80865b2e0>
<KCSUser: 0x7fd80865d970>
<KCSUser: 0x7fd80865e000>
<KCSUser: 0x7fd80865f430>
<KCSUser: 0x7fd808659310>
<KCSUser: 0x7fd8086615d0>
<KCSUser: 0x7fd808658fe0>
<KCSUser: 0x7fd808660420>
<KCSUser: 0x7fd8086637e0>
<KCSUser: 0x7fd808665120>
<KCSUser: 0x7fd808665950>
<KCSUser: 0x7fd8086635d0>
<KCSUser: 0x7fd8086687f0>
<KCSUser: 0x7fd80866a8b0>
<KCSUser: 0x7fd80866b9e0>
<KCSUser: 0x7fd808662f50>
<KCSUser: 0x7fd80866f900>
<KCSUser: 0x7fd80866d950>
<KCSUser: 0x7fd80866eae0>
<KCSUser: 0x7fd8086705c0>
<KCSUser: 0x7fd80866c9f0>
<KCSUser: 0x7fd808673610>
<KCSUser: 0x7fd808670f60>
<KCSUser: 0x7fd808674f90>
<KCSUser: 0x7fd8086775a0>
<KCSUser: 0x7fd8086773b0>
<KCSUser: 0x7fd808675f10>
<KCSUser: 0x7fd808678810>
<KCSUser: 0x7fd80867c450>

 



Elijah,

I have forwarded this to the development team for them to review. Will get back to you as soon as I hear from them.

Thanks,
Pranav
Kinvey Support

 

Any update on this? I am also having this issue. Relational data caching works fine if I don't have user-relations in my entity

Public update: The fix has been deployed as v1.40.8 and is available for download at: http://devcenter.kinvey.com/ios/downloads


Regards,

Wani

Kinvey Support

Login or Signup to post a comment