Clone instance cannot load tasks & targets after replication

Recently we have been monitoring a clone CHT application’s stability after replication and we experienced a few bugs.

First we experienced an issue with tasks & targets page displaying “user is undefined”. To resolve this, We were directed to search if affected user documents were successfully replicated, Thanks to @gareth & @derick

But even after replication was completed and only new data is being streamed in, We still encounter an issue “cannot read properties of undefined (reading: parent)”

Are we still missing some user documents after replication ?

Can you please share which version of CHT you are seeing this on?

It’s hard to tell. Can you confirm that there exist 2 documents for each user on your instance (one in the _users database and one under medic database). The _id for the documents follow this pattern org.user.couchdb:username.

I believe they are testing this on 3.7.1

Yes we are using CHT3.7.1

@derick , I can confirm we do have user documents on both _users and _medic databases as shown the screenshots.

This is on the _user db

Two of the errors (“Error fetching targets” and “Error getting tasks”) are caused by configuration code (where probably some objects are not null-checked before accessing the indicated properties).
The other error (“Error settings selected contact”) looks like an app error.
All of these point to a contact document missing, that both config code and app code expect to exist.

Are you seeing the same error (“Error settings selected contact”) for every contact or just for some contacts?

@diana we have no errors selecting contacts but just accessing the tasks and targets. {The screenshot was taken when I had switched to the people tab from the targets tab}

I will look into objects not being null-checked.

Null checking will resolve the errors being thrown but the app won’t behave as expected because the if condition will resolve false when before you replicated it returned true. For some reason a doc is missing on the phone which used to be there. You could try wiping the phone and syncing again now that the replication to the new server is complete. If it still fails, then it’ll need some more debugging to work out which doc is missing from the phone and/or the new CouchDB instance.

Upon further investigation, keeping in mind that null checkers were part of the solution. We discovered the replication didn’t fully migrate the entire user objects, which was the cause of the issue. Thanks @gareth @diana @derick

1 Like