I 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.
firebase-functions: 2.0.5
firebase-tools: 6.1.1
firebase-admin: 6.0.0
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.
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.
context.params should look like this (and most of the time it does):
{ accountId: '2af276566a9391a81390164d30b46941',
ledgerId: '553cb118-b68e-46b2-afd5-0ef508858264',
transactionId: 'f82c1c5cfea011f8aedfcfe31e411560' }
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.
I am discovering more and more occurrences of this issue today on various Firestore collections. Needless to say this is a very serious problem for any event driven application which utilises Firestore.
Another repro (I am now also logging snapshot.after.ref.path):
path: 'contexts/connections/ledgers/553cb118-b68e-46b2-afd5-0ef508858264/accounts/2af276566a9391a81390164d30b46941/transactions/1e7aece70d469caa21ac379e7c142f37',
params:
{ ledgerId: undefined,
accountId: undefined,
transactionId: undefined },
A workaround that seems to work is to use snapshot.id and snapshot.ref.parent.parent.id, etc. As described here:
https://stackoverflow.com/questions/53792140/cloud-functions-context-params-return-undefined
In 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.
The rollback of the affected jobs is now complete, we expect this to be mitigated for all projects now.
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.
Most helpful comment
A workaround that seems to work is to use
snapshot.idandsnapshot.ref.parent.parent.id, etc. As described here:https://stackoverflow.com/questions/53792140/cloud-functions-context-params-return-undefined
In change triggers the snapshot is available as the
afterproperty, e.g..onUpdate((change, context) => console.log('ID=' + change.after.id))Update: to find the ID of the parent document, you must use
.parent.parenton the reference.