firebase / firebase-functions

Firebase SDK for Cloud Functions
https://firebase.google.com/docs/functions/
MIT License
1.02k stars 201 forks source link

Pubsub onMessagePublished handler does not work #1485

Closed szaleq closed 10 months ago

szaleq commented 10 months ago

[REQUIRED] Version info

node: 18

firebase-functions: 4.5.0

firebase-tools: 12.8.1

firebase-admin: 11.11.0

[REQUIRED] Test case

I have a simple function using v2 pubsub trigger, which should capture published message and save it into firestore. The function looks like this:

const onProfileCreated = onMessagePublished(
    TOPIC_NAME,
    (event) => handleMessagePublished(event.data.message.json) // this function should just store message data in firestore
);

[REQUIRED] Steps to reproduce

Just create a function using onMessagePublished.

[REQUIRED] Expected behavior

I expect the function to get executed with the event containing published message data as a param.

[REQUIRED] Actual behavior

While working perfectly well in local development using firebase emulators, this function's code doesn't get executed when deployed because of an error in firebase-functions code:

TypeError: Cannot read properties of undefined (reading 'messageId')
    at new Message (/workspace/node_modules/firebase-functions/lib/v2/providers/pubsub.js:65:31)
    at func (/workspace/node_modules/firebase-functions/lib/v2/providers/pubsub.js:127:40)

Were you able to successfully deploy your functions?

Yes, I managed to successfully deploy the function, but needed to use gcloud CLI, because when using firebase deploy command, I received an error stating that it failed to create the topic (which is weird, because the topic was already created in pubsub and also the docs say that cloud functions will not create topics and topics should be present during deployment - which was fulfilled).

google-oss-bot commented 10 months ago

I found a few problems with this issue:

blidd-google commented 10 months ago

Hi @szaleq, I'm unable to reproduce the issue using the setup and versions you described above. Can you try deploying again with firebase deploy --debug and share with me the contents of the resulting firebase-debug.log?

google-oss-bot commented 10 months ago

Hey @szaleq. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 10 months ago

Since there haven't been any recent updates here, I am going to close this issue.

@szaleq if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.