firebase-tools: Firestore emulator sending incorrect event payloads to Functions emulator
I just ran a real Cloud Function (non-Firebase) triggered on onWrite
for the document foo/bar
.
I created the document (no previous data) and logged out the two arguments to the function and got this:
context
{
eventId: "6e7a9aae-5e22-4414-abaf-cb6b0a3363a2-0",
eventType: "providers/cloud.firestore/eventTypes/document.write",
notSupported: {},
resource: "projects/fir-dumpster/databases/(default)/documents/foo/bar",
timestamp: "2019-05-14T01:49:26.587519Z",
}
data
{
oldValue: {},
updateMask: {},
value: {
createTime: "2019-05-14T01:49:26.587519Z",
fields: {
hey: {
stringValue: "now",
},
},
name: "projects/fir-dumpster/databases/(default)/documents/foo/bar",
updateTime: "2019-05-14T01:49:26.587519Z",
},
}
However if I do the same thing in the emulator suite I get:
context
{
"eventId": "68ded781-de59-4adb-aff2-a8b6597a9725",
"timestamp": "2019-05-14T01:59:17.900Z",
"eventType": "providers/cloud.firestore/eventTypes/document.write",
"resource": {
"name": "projects/fir-dumpster/databases/(default)/documents/foo/bar",
"service": "firestore.googleapis.com"
}
}
data
{
"value": {
"name": "projects/fir-dumpster/databases/(default)/documents/foo/bar",
"fields": {
"hello": {
"stringValue": "world"
}
},
"createTime": "2019-05-14T01:59:17.900Z",
"updateTime": "2019-05-14T01:59:17.900Z"
},
"updateMask": {}
}
The difference is that in the emulator we get context.resource
is an Object and in prod we get context.resource
is a String.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 16 (15 by maintainers)
I found this issue via https://stackoverflow.com/questions/56587770/firebase-functionsshell-onwrite-property-undefined - but I’m not sure if it is precisely the same issue, or not, so making a quick note here.
I am not able to run RTDB functions in the shell,
context
is undefined on this line:(see https://github.com/firebase/firebase-functions/blob/v3.0.1/src/cloud-functions.ts#L243)