Skip to content

Commit

Permalink
Fix bug where 2nd Gen firestore functions were mistakenly parsed as p…
Browse files Browse the repository at this point in the history
…ubsub 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.
  • Loading branch information
taeold committed Oct 19, 2023
1 parent d675277 commit b7eea76
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Enable [preferRest](https://firebase.google.com/docs/reference/admin/node/firebase-admin.firestore.firestoresettings.md#firestoresettingspreferrest) option by default for Firestore functions. (#6147)
- Fixed an issue with deploying multilevel grouped functions containing v2 functions. (#6419)
5 changes: 4 additions & 1 deletion src/gcp/cloudfunctionsv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,10 @@ export function endpointFromFunction(gcfFunction: OutputCloudFunction): backend.
} else if (gcfFunction.eventTrigger) {
const eventFilters: Record<string, string> = {};
const eventFilterPathPatterns: Record<string, string> = {};
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 || []) {
Expand Down
40 changes: 40 additions & 0 deletions src/test/gcp/cloudfunctionsv2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit b7eea76

Please sign in to comment.