Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions emulator only maintaining last realtime database trigger #1523

Closed
gpfunk opened this issue Jul 18, 2019 · 6 comments · Fixed by #1567
Closed

Functions emulator only maintaining last realtime database trigger #1523

gpfunk opened this issue Jul 18, 2019 · 6 comments · Fixed by #1567

Comments

@gpfunk
Copy link

gpfunk commented Jul 18, 2019

[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

@samtstern
Copy link
Contributor

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

@samtstern
Copy link
Contributor

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

@gpfunk
Copy link
Author

gpfunk commented Jul 18, 2019

god speed :)

@samtstern
Copy link
Contributor

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.

@gpfunk
Copy link
Author

gpfunk commented Jul 18, 2019

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

@samtstern samtstern assigned jmwski and unassigned samtstern Jul 18, 2019
@samtstern
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants