firebase / firebase/firebase-tools

Transaction does not work with GetAll query

Open
#3,348 4 comments 2 reactions 0 assignees View on GitHub
emulator-suite emulators: firestore internal-bug-filed type: feature request
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### [REQUIRED] Environment info

**firebase-tools:** 9.10.2

**Platform:** Ubuntu 20.04.2 LTS

### [REQUIRED] Test case

I am running a transaction to delete a bunch of stuff, but it gives an error right after a `.GetAll()` call

```go

// Delete deletes the given user (removing all of its traces (grades, reviews, etc)
func Delete(DB db.Env, u entity.User) (deleteErr error) {
defer func() {
if r := recover(); r != nil {
deleteErr = r.(error)
}
}()

userHash := u.Hash()
userRef := DB.Client.Doc("users/" + userHash)
finalScores := userRef.Collection("final_scores")
subjectReviews := userRef.Collection("subject_reviews")

deleteErr = DB.Client.RunTransaction(DB.Ctx, func(ctx context.Context, tx *firestore.Transaction) error {
// Do all the reading first
finalScoreRefs, subjectReviewsRefs := tx.DocumentRefs(finalScores), tx.DocumentRefs(subjectReviews)

finalScoresDocs, err := finalScoreRefs.GetAll()
if err != nil { // transaction fails here
return fmt.Errorf("could not get final scores: %v", err.Error())
}
...
}
}
```

### [REQUIRED] Steps to reproduce

Not sure? I am running it like this:
1. Run go test inside firestore emulator: `firebase emulators:exec --only firestore "go test ./server/controllers/account -p 1 -v -race"`
2. Output says `could not get final scores: rpc error: code = Unknown desc = `, which means it failed on the above `err != nil` condition

### [REQUIRED] Expected behavior

Emulator should just return all the document snapshots

### [REQUIRED] Actual behavior

Seems like the error is `INFO: operation failed: transactional listDocuments not implemented`

```
May 08, 2021 1:23:48 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
INFO: Started WebSocket server on ws://localhost:45275
API endpoint: http://localhost:4040
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

export FIRESTORE_EMULATOR_HOST=localhost:4040

Dev App Server is now running.

May 08, 2021 1:24:31 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
May 08, 2021 1:24:31 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
May 08, 2021 1:24:31 PM com.google.cloud.datastore.emulator.impl.util.WrappedStreamObserver onError
INFO: operation failed: transactional listDocuments not implemented
java.lang.UnsupportedOperationException: transactional listDocuments not implemented
at com.google.cloud.datastore.emulator.impl.CloudFirestoreV1.lambda$listDocuments$0(CloudFirestoreV1.java:249)
at com.google.cloud.datastore.emulator.impl.transactions.EmulatorTransactionManager$ReadWriteTransaction.fold(EmulatorTransactionManager.java:261)
at com.google.cloud.datastore.emulator.impl.CloudFirestoreV1.listDocuments(CloudFirestoreV1.java:245)
at com.google.cloud.datastore.emulator.impl.CloudFirestoreV1Router.listDocuments(CloudFirestoreV1Router.java:97)
at com.google.cloud.datastore.emulator.firestore.v1.FirestoreV1GrpcAdapter$1.lambda$listDocuments$2(FirestoreV1GrpcAdapter.java:114)
at com.google.cloud.datastore.emulator.firestore.v1.FirestoreV1GrpcAdapter.unary(FirestoreV1GrpcAdapter.java:67)
at com.google.cloud.datastore.emulator.firestore.v1.FirestoreV1GrpcAdapter.access$000(FirestoreV1GrpcAdapter.java:39)
at com.google.cloud.datastore.emulator.firestore.v1.FirestoreV1GrpcAdapter$1.listDocuments(FirestoreV1GrpcAdapter.java:114)
at com.google.firestore.v1.FirestoreGrpc$MethodHandlers.invoke(FirestoreGrpc.java:1203)
at io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener.onHalfClose(ServerCalls.java:182)
at io.grpc.PartialForwardingServerCallListener.onHalfClose(PartialForwardingServerCallListener.java:35)
at io.grpc.ForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:23)
at io.grpc.ForwardingServerCallListener$SimpleForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:40)
at io.grpc.Contexts$ContextualizedServerCallListener.onHalfClose(Contexts.java:86)
at io.grpc.PartialForwardingServerCallListener.onHalfClose(PartialForwardingServerCallListener.java:35)
at io.grpc.ForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:23)
at io.grpc.ForwardingServerCallListener$SimpleForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:40)
at io.grpc.Contexts$ContextualizedServerCallListener.onHalfClose(Contexts.java:86)
at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:331)
at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1HalfClosed.runInContext(ServerImpl.java:797)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

May 08, 2021 1:24:32 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
May 08, 2021 1:24:32 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
May 08, 2021 1:24:32 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
*** shutting down gRPC server since JVM is shutting down
*** server shut down
```

Sorry if I didn't fill out the issue properly, I'm still a bit new to all of this and I don't really understand how the emulator works :worried:

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.