Firebase-tools: Firestore emulator does not support transactional queries

Created on 6 Aug 2019  路  6Comments  路  Source: firebase/firebase-tools

[REQUIRED] Environment info


7.2.2


firebase-tools: 7.2.2


Platform: macOS 10.14.5

[REQUIRED] Test case

export const myFunction = functions.https.onCall(
    async (data: any, context: CallableContext): Promise<void> => {
        const db = admin.firestore();
        const my_collection: CollectionReference = db.collection(`test_collection`);
        return await db.runTransaction<void>(async (transaction) => {

            const result = await transaction.get(my_collection.doc());
            console.debug(result); // This works

            await transaction.get(my_collection.limit(1));
            // This will crash
        });
});

[REQUIRED] Steps to reproduce

Run firebase emulators:start and call the function from Web App

[REQUIRED] Expected behavior

Emulator should just work as production

[REQUIRED] Actual behavior

Unhandled error Error
at Http2CallStream. (/PATH_TO_PROJECT/functions/node_modules/@grpc/grpc-js/build/src/call.js:68:41)
at Http2CallStream.emit (events.js:208:15)
at /PATH_TO_PROJECT/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:71:22
at processTicksAndRejections (internal/process/task_queues.js:75:11) {
code: 2,
details: '',
metadata: Metadata {
options: undefined,
internalRepr: Map { 'content-type' => [Array] }
}
}

emulator-suite firestore bug

All 6 comments

@ranmocy can you show the complete logs from firebase --debug emulators:start including the failed transaction? Also is there anything in firestore-debug.log?

Thanks for the pointer. firestore-debug.log explains the issue:

Aug 06, 2019 9:59:07 AM com.google.cloud.datastore.emulator.impl.util.WrappedStreamObserver onError
INFO: operation failed: transactional queries not implemented

Is there any plan to implement it? Any tracking bug?

@ranmocy ah yeah that makes sense. We have an internal tracking bug for this issue (since the emulator itself is not open source) but we can leave this one open as well.

@ryanpbrewster we're aware of this limitation, right?

Correct, the internal bug id is 135537114.

For context, the main challenge for this feature is faithfully matching the production Firestore transaction behavior. While you are executing this transaction, are other clients allowed to modify the collection you're querying? The answer for Firestore is fairly complex, and challenging to match exactly. It is likely that when we do implement this in the Firestore emulator we'll be overly pessimistic and allow only a subset of what Firestore actually allows.

That is a reasonable concern.
If you ask me, I would say for an emulator, firstly it should allow any legitimate client code to run against it, and latter to behave as close to production version as possible. So I think it's totally reasonable to minimize the support on concurrency cases.

That being said, would it be possible to have some simple implementation without support of concurrency first? That would allow us to write test for our Firebase functions which rely on Firestore heavily, where mocking Firestore doesn't make a lot sense.

Thanks!

Totally reasonable. There is a bit of work needed in order to support this without breaking the normal concurrency handling, but it's very doable. I'll keep this issue open to track the progress.

Was this page helpful?
0 / 5 - 0 ratings