Firestore trigger: `context.params` sometimes not populated
See original GitHub issueI have had a few Cloud Firestore triggers invoked today with empty context.params
. This is an intermittent issue, and today is the first time I’ve seen this happen. I did not deploy any changes to my cloud functions prior to this issue starting.
Version info
firebase-functions: 2.0.5
firebase-tools: 6.1.1
firebase-admin: 6.0.0
Test case
I have verified the bug by logging context.params
in one of my Firestore onUpdate
triggers using console.log
.
functions.firestore.document(this.firestoreRoot + '/ledgers/{ledgerId}/accounts/{accountId}/transactions/{transactionId}')
.onUpdate((snapshot, {params}) => console.log(params));
To prove the issue, I edit the document /contexts/connections/ledgers/553cb118-b68e-46b2-afd5-0ef508858264/accounts/2af276566a9391a81390164d30b46941/transactions/f82c1c5cfea011f8aedfcfe31e411560
in the Firebase console and observe the logs to record the actual shape of context.params
during the trigger invocation.
Were you able to successfully deploy your functions?
I was able to deploy my functions. There were no errors. These functions were deployed weeks ago and have been invoked correctly thousands of times during that period.
Expected behavior
context.params
should look like this (and most of the time it does):
{ accountId: '2af276566a9391a81390164d30b46941',
ledgerId: '553cb118-b68e-46b2-afd5-0ef508858264',
transactionId: 'f82c1c5cfea011f8aedfcfe31e411560' }
Actual behavior
Today, context.params
sometimes looks like this:
{ ledgerId: undefined,
accountId: undefined,
transactionId: undefined }
As you can see, the params are undefined
, not 'undefined'
, so I don’t think these params are even valid (document ID’s must be strings). Something is very wrong here.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:5 (1 by maintainers)
A workaround that seems to work is to use
snapshot.id
andsnapshot.ref.parent.parent.id
, etc. As described here: https://stackoverflow.com/questions/53792140/cloud-functions-context-params-return-undefinedIn change triggers the snapshot is available as the
after
property, e.g..onUpdate((change, context) => console.log('ID=' + change.after.id))
Update: to find the ID of the parent document, you must use
.parent.parent
on the reference.Hi all, confirming that this was an issue with a rollout on our side, which we have now rolled back. I understand your frustration and apologize about the incident. We will be investigating into the reasons why this occurred. Internal bug reference: 121064658.
There is another issue on this that you’ve correctly referenced here, so I’m going to close this out. Please follow for updates on #358.