python-3.xgoogle-cloud-pubsubfunctions-frameworkgoogle-cloud-pubsub-emulator

Google Pub/Sub - No event data found from local function after published message to topic


I'm using the Functions Framework with Python alongside Google Cloud Pub/Sub Emulator. I'm having issues with an event triggered from a published message to a topic, where there's no event data found for the function. See more details below.

  1. Topic is created as test-topic
  2. Function is spinned up under http://localhost:8007.
  3. Create push subscription test-subscription for test-topic for endpoint: http://localhost:8007

When I publish a message to test-topic from http://localhost:8006 via POST request in Postman, I get back a 200 response to confirm the message was published successfully. The function representing http://localhost:8007 gets executed as an event as shown in the logs from the functions-framework. However, there's no actual data for event when debugging the triggered function.

Has anyone encountered this? Any ideas/suggestions on this?
Perhaps, this is true? #23 Functions Framework does not work with the Pub/Sub emulator

Modules Installed

python version


Solution

  • I'll close this post, since the issue is an actual bug that was reported last year.

    Update: As a workaround until this bug is fixed, I copied the code below locally to functions_framework/__init__.py within view_func nested function, inside _event_view_func_wrapper function.

    if 'message' in event_data:
        if 'data' not in event_data:
            message = event_data['message']
            event_data['data'] = {
                'data': message.get('data'),
                'attributes': message.get('attributes')
            }