firebase / firebase/firebase-tools
Params are randomized when using shell to test firestore triggered function w/ emulated firestore instance
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.3k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 84
Description
### [REQUIRED] Environment info
**firebase-tools:** 11.1.0
**Platform:** Ubuntu-22.04 via WSL2 on Windows 11
### [REQUIRED] Test case
What I want to do is:
- Emulate Firestore
- Have a function that gets triggered when a write event occurs on Firestore
- Retrieve the wildcards that you can pass as parameters (as explained in https://firebase.google.com/docs/functions/local-shell) when calling the function from the local shell
- Use the wildcards for other interactions with Firestore (specific use not relevant, and not explained here)
However, it seems like somewhere along the way those parameters get randomized. See below for an example.
The issue only occurs when Firestore is emulated and functions are invoked from the shell. Wildcards seem to work fine on the actual Firebase project.
The problem could be with any of the functions shell, the Firestore emulator, or the library that handles the Firestore triggers. A wild guess is that somewhere in there, there is a flag that checks the environment, and if Firestore is being emulated then the wildcards are randomized.
### [REQUIRED] Steps to reproduce
- Create the following function (very minimal for the sake of simplicity):
`export const test = functions.firestore.document('properties/{postcode}/addresses/{address}/reviews/{review}').onWrite((change, context) => {
console.log(context.params);
return 'See? Params change!';
});`
- Transpile with `tsc`
- Run `firebase emulators:start --only firestore`
- Run `firebase functions:shell`
- Make this invocation `firebase > test({before:{foo: "bar"},after:{fee: "beer"},params:{postcode:"SW6_7JX",address:"10_Kilmaine_Road",review:"review_1"}})`
### [REQUIRED] Expected behavior
Output should be:
> 'Successfully invoked function.'
> { postcode: 'SW6_7JX', address: '10_Kilmaine_Road', review: 'review_1' }
### [REQUIRED] Actual behavior
Output is:
> 'Successfully invoked function.'
> { postcode: 'postcode5', address: 'address4', review: 'review1' }
Contributor guide
Research direction
Reproduce the issue with the shown TypeScript function, `firebase emulators:start --only firestore`, and `firebase functions:shell` using the supplied parameters. Trace the functions shell and Firestore emulator invocation path to find where the provided wildcards become generated values; done means `context.params` contains `SW6_7JX`, `10_Kilmaine_Road`, and `review_1`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- firebase, typescript
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100