From ecd78051191bb2d3ed57c796252478a6299538a5 Mon Sep 17 00:00:00 2001 From: Daniel Young Lee Date: Wed, 18 Oct 2023 17:04:24 -0700 Subject: [PATCH 1/2] Fix bug where 2nd Gen firestore functions were mistakenly parsed as pubsub function. 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 https://github.com/firebase/firebase-tools/issues/6453. --- src/gcp/cloudfunctionsv2.ts | 5 +++- src/test/gcp/cloudfunctionsv2.spec.ts | 40 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/gcp/cloudfunctionsv2.ts b/src/gcp/cloudfunctionsv2.ts index 8f935952ff3..2b3ee1a64ab 100644 --- a/src/gcp/cloudfunctionsv2.ts +++ b/src/gcp/cloudfunctionsv2.ts @@ -661,7 +661,10 @@ export function endpointFromFunction(gcfFunction: OutputCloudFunction): backend. } else if (gcfFunction.eventTrigger) { const eventFilters: Record = {}; const eventFilterPathPatterns: Record = {}; - if (gcfFunction.eventTrigger.pubsubTopic) { + if ( + gcfFunction.eventTrigger.pubsubTopic && + gcfFunction.eventTrigger.eventType === PUBSUB_PUBLISH_EVENT + ) { eventFilters.topic = gcfFunction.eventTrigger.pubsubTopic; } else { for (const eventFilter of gcfFunction.eventTrigger.eventFilters || []) { diff --git a/src/test/gcp/cloudfunctionsv2.spec.ts b/src/test/gcp/cloudfunctionsv2.spec.ts index ce9724d8969..60e34b14799 100644 --- a/src/test/gcp/cloudfunctionsv2.spec.ts +++ b/src/test/gcp/cloudfunctionsv2.spec.ts @@ -475,6 +475,46 @@ describe("cloudfunctionsv2", () => { }, }) ).to.deep.equal(want); + + // And again with a pattern match event trigger + want = { + ...want, + eventTrigger: { + eventType: "google.cloud.firestore.document.v1.written", + eventFilters: { + database: "(default)", + namespace: "(default)", + }, + eventFilterPathPatterns: { + document: "users/{userId}", + }, + retry: false, + }, + }; + expect( + cloudfunctionsv2.endpointFromFunction({ + ...HAVE_CLOUD_FUNCTION_V2, + eventTrigger: { + eventType: "google.cloud.firestore.document.v1.written", + eventFilters: [ + { + attribute: "database", + value: "(default)", + }, + { + attribute: "namespace", + value: "(default)", + }, + { + attribute: "document", + value: "users/{userId}", + operator: "match-path-pattern", + }, + ], + pubsubTopic: "eventarc-us-central1-abc", // firestore triggers use pubsub as transport + }, + }) + ).to.deep.equal(want); }); it("should translate custom event triggers", () => { From 9b0e005151dfd13edcb402df79b84d43111c56cc Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Wed, 18 Oct 2023 17:07:42 -0700 Subject: [PATCH 2/2] Add changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bde97673fe5..ed237e5bf53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,2 @@ - Fixed an issue with deploying multilevel grouped functions containing v2 functions. (#6419) +- Fix bug where re-deploying 2nd Gen Firestore function fails after updating secrets. (#6456)