question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firestore trigger: `context.params` sometimes not populated

See original GitHub issue

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.

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:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
rmacfiecommented, Dec 15, 2018

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.

0reactions
thechenkycommented, Dec 17, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cloud Firestore triggers | Cloud Functions for Firebase
Note: Cloud Firestore events will trigger only on document changes. An update to a Cloud Firestore document, where data is unchanged (a no-op...
Read more >
Firestore suddenly has a huge trigger delay - Stack Overflow
The problem can be due to the monotonically increasing orderId as the parameter passed here: ... .collection("orders") .doc(context.params.
Read more >
Cloud Firestore collections, triggers, & more! #AskFirebase
Host Jen Person, and guest Todd Kerpelman (from our series Get to Know Cloud Firestore ) team up to answer all your burning...
Read more >
Patterns for security with Firebase: combine rules with Cloud ...
At first glance, the EventContext object passed as the second parameter to Cloud Firestore triggers looks like it has auth data in it....
Read more >
Using Firestore with IoT Core for device configuration
If you do not already have a development environment set up with the ... You use a Firestore document trigger to run a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found