firebase / firebase/firebase-tools

Emulators for functions v2 not supporting different regions

Open
#7,580 5 comments 6 reactions 1 assignee Claimed by @ajperel View on GitHub
emulators: functions type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### [REQUIRED] Environment info

**firebase-tools:**13.15.4

**Platform:**macOS

### [REQUIRED] Test case

index.ts:
```typescript
import { onValueCreated } from "firebase-functions/v2/database";
import { setGlobalOptions } from "firebase-functions/v2";
import { region } from "firebase-functions/v1";

setGlobalOptions({ region: "europe-west1" });

export const NewInQueueV1 = region("europe-west1")
.database.ref("mailing/queue/{pushID}/")
.onCreate(() => {
console.log("There is a new mail in the mailing queue (v1)");
});

export const NewInQueueV2 = onValueCreated("mailing/queue/{pushID}/", () => {
console.log("There is a new mail in the mailing queue (v2)");
});
```

### [REQUIRED] Steps to reproduce

Create a new project with the default firebase in region `europe-west1` and run the firebase functions and database emulators.
Using the emulators ui, import the following json:
```json
{
"mailing": {
"queue": {
"somePushID": {
"email": "test@email.com",
"action": "whitelist"
}
}
}
}
```
making sure the checkbox "Also execute database triggers in the Functions emulator" is checked.
Observe the log.

### [REQUIRED] Expected behavior

Both functions should be initialised without warning and on importing the json, both console.log statements should be executed indicating both functions were triggered.

### [REQUIRED] Actual behavior

The v2 version warns about `functions[europe-west1-NewInQueueV2]: function region is defined outside the database region, will not trigger.`. On import, only the v1 functions Is triggered. Even when repeating the setup without the v1 function in index.ts (in case a second function triggering on the same path would be a problem), the v2 function does not get triggered.

I found [the following code](https://github.com/firebase/firebase-tools/blob/master/src/emulator/functionsEmulator.ts#L961):
```
// TODO(colerogers): yank/change if RTDB emulator ever supports multiple regions
if (region !== "us-central1") {
this.logger.logLabeled(
"WARN",
`functions[${id}]`,
`function region is defined outside the database region, will not trigger.`,
);
}
```
Where the comment together with the if clause seems to indicate that regions other than `us-central1` are not supported in the emulators. (so I guess this might be interpreted as a feature request instead of an issue?)

Also, the warning message itself is misleading, since it infers the location of the database is wrong, but I believe the message is shown based on the region of the function. In this case, since the region is prepended to the function name, the warning seems to indicate that the referenced database is not in the preferred region `europe-west1`, when the warning is due to the region of the function, not the database.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.