-
Notifications
You must be signed in to change notification settings - Fork 979
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
Firebase Emulator error when writing/updating document inside a Firestore trigger, when using snapshot.ref.set() #1682
Comments
@ralcar thanks that's an interesting bug, I think I can see how it happened. For now you can workaround this by doing: const newRef = admin.firestore().doc(snapshot.ref.path);
return newRef.set({ ... }); This will construct a new reference using the emulated |
Note to self: I think we could get around this by initializing an app with the name |
Thank you for the quick answer, that worked great, thank you! Was worried i was going to have to build that path everywhere. This is cleaner, but I hope I could avoid importing the firebase-admin at all in the future ;). Just for some more help with the debugging, i initializeApp on two different databases during bootup of the cloud functions. And i am locally on Node 10.15.1 |
@ralcar could you show the code where you initializeApp twice? It would be helpful so that I can recreate the situation. |
I saw something similar using Weirdly enough though, |
@larssn that sounds correct. |
Sorry, I should have mentioned what kind of trigger it was, as it was the |
@samtstern ofcourse, here it is!
|
@ralcar thanks! FYI |
@larssn yes the doc should definitely exist at this point. I worry that your code is talking to prod sometimes ... changing it to |
Working on this over here: |
The fix for this issue has been released in version |
[REQUIRED] Environment info
firebase-tools:
7.4.0
Platform:
Windows
[REQUIRED] Test case
Since auth is not available in the context for Firestore triggers, I send along some user data in the snapshot to log the activity and use the user token to create some extra steps inside the onCreate function. I extract the userdata from the snapshot and the want to remove the userdata using the snapshot.ref.set(snapShotWithoutUserData)
[REQUIRED] Steps to reproduce
I have tried ref.set(), ref.update() with or without the merge parameter, same result
[REQUIRED] Expected behavior
Expect it to run without errors as it does when i deploy it.
[REQUIRED] Actual behavior
The emulator/trigger crashes, giving this error
If i deploy the same code and run it without the emulator, it works just fine. Or if i use the firebase-admin to do the same task by building the path using the context params, it also works
! Non-default "firebase-admin" instance created!
! Google API requested!
! functions: Error: Getting metadata from plugin failed with error: invalid_grant
at Http2CallStream.call.on (C:\Development<projectId>\functions\node_modules@grpc\grpc-js\build\src\client.js:96:45)
at Http2CallStream.emit (events.js:194:15)
at Http2CallStream.EventEmitter.emit (domain.js:441:20)
at process.nextTick (C:\Development<projectId>\functions\node_modules@grpc\grpc-js\build\src\call-stream.js:71:22)
at process._tickCallback (internal/process/next_tick.js:61:11)
! Your function was killed because it raised an unhandled error.
(node:13324) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are
sent to the client
at ServerResponse.setHeader (_http_outgoing.js:470:11)
at ServerResponse.header (C:\Users\ralcar\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\express\lib\response.js:771:10)
at ServerResponse.send (C:\Users\ralcar\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\expressginated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
The text was updated successfully, but these errors were encountered: