Firestore WriteBatch Fails to execute when using s

2019-08-27 04:36发布

I am building an Android application using Firestore as my backend. I am writing to multiple collections within a document, and in some instances can write to a document, update the document, then delete the document all within the same WriteBatch. Whenever a user creates, then later deletes a document within the same WriteBatch my application crashes. Below is the code and error I receive.

private void executeBatchedWrite() {
    WriteBatch batch = db.batch();

    DocumentReference doc = notebookRef.document("123");
    batch.set(doc, new Note("New Note", "New Note", 1));

    batch.update(doc, "timestamp", FieldValue.serverTimestamp());

    batch.delete(doc);

    batch.commit();
}

My app crashes and I receive the following error:

java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
    at com.google.firebase.firestore.g.zza.zzb(SourceFile:324)
    at com.google.firebase.firestore.g.zzd.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)

1条回答
甜甜的少女心
2楼-- · 2019-08-27 04:50

I've determined this was a bug and reported it to Google. Further testing indicates that this issue may be specific to writing FieldValue.serverTimestamp() to a document that will eventual be deleted within the same batch write. If the FieldValue.serverTimestamp() is replaced with a different value (ex: System.currentTimeMillis()), the issue seems to go away.

查看更多
登录 后发表回答