Firebase-tools: Functions emulator only maintaining last realtime database trigger

Created on 18 Jul 2019  ·  6Comments  ·  Source: firebase/firebase-tools

[REQUIRED] Environment info


firebase-tools:
firebase: 7.1.1
node: v10.16.0
java: 11.0.2


Platform:
macOS

[REQUIRED] Test case

It appears at this line, firebase-tools/functionsEmulator.ts at dad143c42445056014f6f48cc9dfa13156e3c186 · firebase/firebase-tools · GitHub
, the request to add a new trigger is overriding the previous triggers added rather than being added to the list

[REQUIRED] Steps to reproduce

curl 'http://localhost:9000/.settings/functionTriggers.json?ns=test-project' -X PUT -H 'authorization: Bearer owner' --data-binary '[{"name":"projects/test-project/locations/_/functions/NewPost","path":"/posts/{ownerId}/{postId}","event":"providers/google.firebase.database/eventTypes/ref.create","topic":"projects/test-project/topics/NewPost"}]' --compressed
{"status":"ok"}

curl 'http://localhost:9000/.settings/functionTriggers.json?ns=test-project' -H 'authorization: Bearer owner' --compressed
[{"name":"projects/test-project/locations/_/functions/NewPost","path":"/posts/{ownerId}/{postId}","event":"providers/google.firebase.database/eventTypes/ref.create","topic":"projects/test-project/topics/NewPost"}]

curl 'http://localhost:9000/.settings/functionTriggers.json?ns=test-project' -X PUT -H 'authorization: Bearer owner' --data-binary '[{"name":"projects/test-project/locations/_/functions/UpdatePost","path":"/posts/{ownerId}/{postId}","event":"providers/google.firebase.database/eventTypes/ref.update","topic":"projects/test-project/topics/UpdatePost"}]' --compressed
{"status":"ok"}

curl 'http://localhost:9000/.settings/functionTriggers.json?ns=test-project' -H 'authorization: Bearer owner' --compressed
[{"name":"projects/test-project/locations/_/functions/UpdatePost","path":"/posts/{ownerId}/{postId}","event":"providers/google.firebase.database/eventTypes/ref.update","topic":"projects/test-project/topics/UpdatePost"}]

[REQUIRED] Expected behavior

Both of the database triggers would be added and listed in the database emulator

[REQUIRED] Actual behavior

Each call is overriding the previous call

emulator-suite database functions bug

All 6 comments

@gpfunk thanks for reporting this! I will investigate this now and see if I can reproduce.

Confirmed this is a bug, now to find where it lives.

god speed :)

Ok this is one of those "working as intended but still a bug" things. Basically the firebase-tools code (as you noticed) is sending a PUT to the entire functionTriggers resource for each function, which replaces it.

What we really need is an "upsert" operation implemented in the RTDB emulator that we can call using a trigger name as a unique ID. This is what Firestore has. We'll talk about it today and hopefully get a solution.

Thought that may be the case, thanks for the quick feedback!

@IanWyszynski is going to try and add an "upsert" operation.

Was this page helpful?
0 / 5 - 0 ratings