Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.62k stars 600 forks source link

RecordId was sent over the bridge, but it's not cached #1014

Open sharmapr25 opened 3 years ago

sharmapr25 commented 3 years ago

While working on sync api implementation, data was not getting synced with the back-end server. As I debug the issue using react-native log-android for android apk it is giving the below error:

{ [Diagnostic error: Record ID customEvent#eeqpmwlxhbfspqje was sent over the bridge, but it's not cached]
                             │ framesToPop: 2,
                             │ name: 'Diagnostic error',
                             │ line: 686,
                             │ column: 197,
                             └ sourceURL: 'index.android.bundle' }

I have checked the previous raised same issue (https://github.com/Nozbe/WatermelonDB/issues/546). According to given pr

https://github.com/Nozbe/WatermelonDB/pull/593/commits/e218e65fe8a22ed67960589266c2f2c9acfd807f#diff-16c5647a7c7453a2dfe53b0c02b910d61b56a868a0722d40aca64061bade48a3 it is fixed. After updating to the latest code I am still getting this error.

So recreating the same issue. Any idea?

sharmapr25 commented 3 years ago

@radex After debugging the watermelondb library, I have found a weird issue:

While using sync API it fetches local changes from the database, where it makes a query of fetching records that do not have _status as synced. Some record ids fetched by query don't exist in the record cache.

Following are the logs in watermelondb files

[14:11:15] I | ReactNativeJS ▶︎  { [Diagnostic error: Record ID customEvent#cq2tq3zj5kia5owq was sent over the bridge, but it's not cached]
                             │ framesToPop: 2,
                             │ name: 'Diagnostic error',
                             │ line: 686,
                             │ column: 197,
                             │ sourceURL: 'index.android.bundle' }
                             │ cache record is:  [object Object] and id: ugmowgv6vp5qv4ij and map size is: 1
                             └ map has record id: ugmowgv6vp5qv4ij

In RecordCache.js _cachedModelForId function log

[14:12:15] I | ReactNativeJS ▶︎ cache record is:  undefined and id: cq2tq3zj5kia5owq and map size is: 31
                             │ map has record id: 8hw1f9jj1673ukfs
                             │ map has record id: bfzjgq02qlb2o4hp
                             │ map has record id: t2rt9vol63v90i9a
                             │ map has record id: 80t5c3h255a8k27d
                             │ map has record id: mkhhsurygday46gm

I have tracked the log, there is no clearing/resetting of cache also. Even given record id cq2tq3zj5kia5owq has not been set in record cache. Any idea why this record id is available in the query [const notSyncedQuery = Q.where(columnName('_status'), Q.notEq('synced'))]?

customEvent is only creating data

await this.eventCollection.create(event => {
            Object.assign(event, eventData);
            event.sessionId.set(sessionId);  
});
KrisLau commented 2 years ago

I'm having a similar problem which is caused by using integer as the _id. Did you ever figure this out?