Cloud events incorrectly unmarshalled: first argument is undefined, 2nd argument differs from production
See original GitHub issueWhen Pubsub notifications are sent to a locally hosted cloud event function, the first argument is undefined. It should contain the event information. The 2nd argument though present, does not match production signature; rather than containing metadata about the notification, it contains the entire event object, which should be the contents of argument 1 instead.
My dummy cloud events function:
exports.helloEvents = (data, context) => {
console.log(data);
console.log(context);
};
Pub/sub notification being sent:
{
"subscription": "projects/myproj/subscriptions/mysub",
"message": {
"data": "...my base 64 encoded data...",
"messageId": "1",
"attributes": {}
}
}
helloEvents log in production:
Argument 1, data, is:
{
"subscription":"projects/myproj/subscriptions/mysub",
"message":{
"data":"...my base 64 encoded data...",
"messageId":"1",
"attributes":{}
}
}
Argument 2, context, is:
{
"eventId":"12032d95-089a-4663-9be5-8aafd9d4c623",
"resource":{
"service":"pubsub.googleapis.com",
"name":"projects/myproj/topics/mytopic"
},
"eventType":"google.pubsub.topic.publish",
"timestamp":"2019-06-16T18:39:44.809Z"
}
On local, the results I get is very different.
- Argument 1: undefined
- Argument 2:
{
"subscription":"projects/myproj/subscriptions/mysub",
"message":{
"data":"...my base 64 encoded data...",
"messageId":"1",
"attributes":{}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:13
- Comments:14 (1 by maintainers)
Top Results From Across the Web
Write event-driven functions | Cloud Functions Documentation
Event -driven functions in the Cloud Functions (1st gen) Node.js, Python, Go, and Java runtimes expect different arguments from CloudEvent functions.
Read more >Strange second argument passed to event handler (always ...
The event listener called with 2 arguments: synthetic event and strange undefined value. I think, normal behavior is when handler called with a ......
Read more >XDK for Java XML Error Messages - Oracle Help Center
Cause: The content model in the element declaration was invalid, the content particle requires an element name. See Production [48] in XML 1.0...
Read more >RHSA-2021:3759 - Security Advisory - Red Hat Customer Portal
Red Hat OpenShift Container Platform is Red Hat's cloud computing Kubernetes application platform solution designed for on-premise or ...
Read more >Kogito Documentation - Red Hat on GitHub
The kogito.codegen.sources.directory parameter defines the custom target ... The custom {KOGITO} Service is now configured to produce cloud events that will ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hey all, thanks for the comments. I know this is an issue. I’m not sure of the exact solution right now.
We’re formally supporting CloudEvents in the Functions Framework spec and will be looking at better, more accurate support for CloudEvents (and legacy events) in the frameworks.
I’ve pinged a colleague to see if we can also improve our docs on cloud.google.com
I’ve removed that section until we have accurate docs.
@alexsanzdev the tests pass, but I don’t believe that they are terribly comprehensive. There is no test data that looks anything like the Cloud Pub/Sub request.
Incidentally, there is test data named “GCF legacy event” that looks like this:
So it seems like maybe there should be a test for the PubSub event format, and the associated fix to pull data from correct place, but I’m still stuck scratching my head asking how this works on GCF production.
In any case, this whole section seems to be flat wrong, because following the approach simply doesn’t work.