google / ground-android

Ground mobile data collection app for Android

Home Page:http://groundplatform.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Data sync] Can't sync new LOI and data with photos

gino-m opened this issue · comments

Collecting data with photo and text tests fails without printing stack trace. Using debugger, I caught the following in LocalMutationSyncWorker:124:

java.lang.ClassCastException: com.google.android.ground.model.submission.TextTaskData cannot be cast to com.google.android.ground.model.submission.PhotoTaskData
	at com.google.android.ground.persistence.remote.firebase.protobuf.ModelToProtoExtKt.toMessage(ModelToProtoExt.kt:170)
	at com.google.android.ground.persistence.remote.firebase.protobuf.ModelToProtoExtKt.createSubmissionMessage(ModelToProtoExt.kt:78)
	at com.google.android.ground.persistence.remote.firebase.schema.SubmissionDocumentReference.addMutationToBatch(SubmissionDocumentReference.kt:35)
	at com.google.android.ground.persistence.remote.firebase.FirestoreDataStore.addSubmissionMutationToBatch(FirestoreDataStore.kt:125)
	at com.google.android.ground.persistence.remote.firebase.FirestoreDataStore.applyMutations(FirestoreDataStore.kt:96)
	at com.google.android.ground.persistence.sync.LocalMutationSyncWorker.processMutations(LocalMutationSyncWorker.kt:118)
	at com.google.android.ground.persistence.sync.LocalMutationSyncWorker.access$processMutations(LocalMutationSyncWorker.kt:43)
	at com.google.android.ground.persistence.sync.LocalMutationSyncWorker$processMutations$2.invokeSuspend(Unknown Source:15)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)

It appears photo tasks are still being stored in mutations under newTaskData as TextTaskData instead of PhotoTaskData. I suggest fixing at the source and adding a throw/catch to report this in logs.

@shobhitagarwal1612 @scolsen It appears the problem is that ValueJsonConverter still converts photos to TextTaskData when loading from the local db, and only stores the remote path to the local mutation queue. We would also need to full local path to be able to queue up uploads in the media sync worker.

It looks like we have a hack in UserMediaRepository::getLocalFileFromRemotePath to reconstruct the local path to work around this fact.

Working around this and filing #2615 to track better fix.