Skip to content

Commit b7eea76

Browse files
authored
Fix bug where 2nd Gen firestore functions were mistakenly parsed as pubsub function (#6456)
Firestore trigger also includes pubsubTopic since they use pubsub as transport. This triggered a bug where 2nd Gen Firestore bugs were being parsed as pubsub function which manifests in bugs like #6453.
1 parent d675277 commit b7eea76

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Enable [preferRest](https://firebase.google.com/docs/reference/admin/node/firebase-admin.firestore.firestoresettings.md#firestoresettingspreferrest) option by default for Firestore functions. (#6147)
2+
- Fixed an issue with deploying multilevel grouped functions containing v2 functions. (#6419)

src/gcp/cloudfunctionsv2.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,10 @@ export function endpointFromFunction(gcfFunction: OutputCloudFunction): backend.
661661
} else if (gcfFunction.eventTrigger) {
662662
const eventFilters: Record<string, string> = {};
663663
const eventFilterPathPatterns: Record<string, string> = {};
664-
if (gcfFunction.eventTrigger.pubsubTopic) {
664+
if (
665+
gcfFunction.eventTrigger.pubsubTopic &&
666+
gcfFunction.eventTrigger.eventType === PUBSUB_PUBLISH_EVENT
667+
) {
665668
eventFilters.topic = gcfFunction.eventTrigger.pubsubTopic;
666669
} else {
667670
for (const eventFilter of gcfFunction.eventTrigger.eventFilters || []) {

src/test/gcp/cloudfunctionsv2.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,46 @@ describe("cloudfunctionsv2", () => {
475475
},
476476
})
477477
).to.deep.equal(want);
478+
479+
// And again with a pattern match event trigger
480+
want = {
481+
...want,
482+
eventTrigger: {
483+
eventType: "google.cloud.firestore.document.v1.written",
484+
eventFilters: {
485+
database: "(default)",
486+
namespace: "(default)",
487+
},
488+
eventFilterPathPatterns: {
489+
document: "users/{userId}",
490+
},
491+
retry: false,
492+
},
493+
};
494+
expect(
495+
cloudfunctionsv2.endpointFromFunction({
496+
...HAVE_CLOUD_FUNCTION_V2,
497+
eventTrigger: {
498+
eventType: "google.cloud.firestore.document.v1.written",
499+
eventFilters: [
500+
{
501+
attribute: "database",
502+
value: "(default)",
503+
},
504+
{
505+
attribute: "namespace",
506+
value: "(default)",
507+
},
508+
{
509+
attribute: "document",
510+
value: "users/{userId}",
511+
operator: "match-path-pattern",
512+
},
513+
],
514+
pubsubTopic: "eventarc-us-central1-abc", // firestore triggers use pubsub as transport
515+
},
516+
})
517+
).to.deep.equal(want);
478518
});
479519

480520
it("should translate custom event triggers", () => {

0 commit comments

Comments
 (0)